I'm currently making a program and I want to take a input of either "Red" or "Black" and then a number from 1-10.
Input should look like Red 7
or Black 3
I want the program to reprint the line if the input is invalid. I was thinking about using a try { and then catch {. But I'm unsure what condition to check.
I tried this:
System.out.print("Please choose Black or Red....and a number from 1-10 (Example : Black 4): ");
String color = input.next();
int number = input.nextInt();
if(!color.equals("Red") || !color.equals("red") || !color.equals("Black") || !color.equals("black")) {
System.out.println("Incorrect input. Please enter Black or Red: ");
color = input.next();
}
if(!(number < 0 || number > 10)) {
System.out.println("Incorrect input. Please re-enter a valid number from 1 to 10: ");
color = input.next();
}