I keep getting "invalid entry" although I'm typing in "typeA" when running this program to check if it's working. Please let me know what my mistake is.
import java.util.Scanner;
public class taxcalc {
public static void main(String []args){
Scanner input = new Scanner(System.in);
String type;
int typeAinc, typeBinc, typeCinc, noTypeA, noTypeB, noTypeC;
noTypeA = 0;
noTypeB = 0;
noTypeC = 0;
int totalIncome = 0;
do {
System.out.println("Enter the customer type as typeA, typeB or typeC; Enter 'done' when you're finished, and remember that your input is case-sensitive!");
type = input.next();
if (type != "typeA" && type != "typeB" && type != "typeC" && type != "done") {
System.out.println("Entry is not valid!");
} else if (type == "typeA") {
noTypeA = noTypeA + 1;
} else if (type == "typeB") {
noTypeB = noTypeB + 1;
} else if (type == "typeC") {
noTypeC = noTypeC + 1;
} else {
System.out.println("The program will terminate soon!");
}
} while (type != "done");
}
}
Aucun commentaire:
Enregistrer un commentaire