System.out.print("Hi " + name + ", which do you choose? (O)dds or (E)vens? ");
String userChoice = null;
while ((!userChoice.equals("O")) || (!userChoice.equals("E"))) {
userChoice = input.nextLine();
}
if ( userChoice.equals("O") ) {
System.out.println(name + " has picked odds! The computer will be evens.");
} else {
System.out.println(name + " has picked evens! The computer will be odds.");
}
Cheers guys,
I am new to Java and I have no clue why this is not working. I want to ask the user for his choice until he chooses "O" or "E". Otherwise re-ask the user for his input. Therefore my idea was to check if userChoice does not equal "O" or "E" > ask again.
Thank you in advance for your help!
I get this error when running the code:
Let´s play a game called "Odds and Evens" What is your name? Ron Hi Ron, which do you choose? (O)dds or (E)vens? Exception in thread "main" > java.lang.NullPointerException at com.ronwalter.Main.main(Main.java:18) Process finished with exit code 1