jeudi 21 novembre 2019

If else statement not working when user tries to skip [duplicate]

This question already has an answer here:

The "Else" part works fine (i.e. if I enter a number), it's just when I enter Skip that I get a whole bunch of errors, any suggestions?

System.out.println("Type 'Skip' to skip. I would like to check how many members joined in month: ");

String userInput = scan.next().toUpperCase();

if (userInput == "SKIP") {
  System.out.println("Placeholder");
}

else {
 int month = Integer.parseInt(userInput);

  if (month>=0 && month <=12) {
   System.out.println(club.joinedInMonth(month) + " member(s) joined in month " + month + ".");
  }
  else {
   System.out.println("Error, month must be between 1 & 12");
        }
}

Aucun commentaire:

Enregistrer un commentaire