I am trying to accept only three numbers from my input: 1, 2, 3. Any other different than that must be invalid. I have created method but I don't have an idea why it did not working. What must I change?
int number;
do {
System.out.println("Enter 1, 2 or 3");
while (!scanner.hasNextInt()) {
System.out.println("Invalid input!");
}
number = scanner.nextInt();
} while (number == 1 || number == 2 || number == 3)
return number;