This question already has an answer here:
- How do I compare strings in Java? 23 answers
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
double income;
String status;
double tax = 0;
System.out.println("Please enter your maritial status: ");
status = sc.next();
System.out.println("Please enter your income: ");
income = sc.nextDouble();
if (status == "single"){
if (income >= 32000){
tax = (3200+0.25)*(income - 32000);
}else{
tax = 0.1 * income;
}
}else
if (status == "married")
if (income >= 64000)
tax = (6400 + 0.25) * (income - 64000);
else
tax = 0.1 * income;
else{
System.out.println("Invalid");
}
System.out.println("Your tax payable is : $" + tax);
}
}
Code doesn't seem to work properly it keeps giving me Invalid whenever i try single with $33000 or any other inputs
Aucun commentaire:
Enregistrer un commentaire