Quote:
Originally Posted by Ooble
Let's format that the way Java sees it (after we fix the = problem):
if (number == "1")
if (number == "2")
if (number == "3")
if (number == "4")
if (number == "a")
if (number == "b")
System.out.println ("Congratulations you entered " + number);
else
System.out.println("You have entered an invalid key " + number); Understand why it's broken now? You're checking to see whether number == "1", and then checking to see whether number == "2"... obviously both of these can't be true, so it fails.
Try this:
if (number == "1" || number == "2" || number == "3" ||
number == "4" || number == "a" || number == "b")
System.out.println("Congratulations you entered " + number);
else
System.out.println("You have entered an invalid key " + number);
|
Thank you very much for your help, but unfortunately this didn't work, I tried it with your code and this is the error. You can see it in the attached pic.