I'm a relatively new Java student, and I was recently trying to mix the scanner tool with if-else-if. Every time I try to run the program and I input M,m,F, or f, I run into my last "else" where it ends the program and tells me that my input is invalid
System.out.print("Please enter your gender (M/F): ");
String Gender = in.nextLine();
if ((Gender == "M") || (Gender == "m"))
System.out.println("MALE");
else if ((Gender == "F") || (Gender == "f"))
System.out.println("FEMALE");
else
{
System.out.println("");
System.out.println("Invalid Input For Gender!");
System.out.println("Please Try Again!");
System.exit(0);
}
Aucun commentaire:
Enregistrer un commentaire