0
Help with input after if statement
New to java here and I have a project due. Basically the question is asking what your favorite ROYGBIV color is and if you do not know to enter âhelpâ that prints the list of colors to choose from. But now I need the user to be given another chance to input their color after they have seen the list of available colors to choose from. If you do not enter âhelpâ and enter a color than it works fine and moves on to the next question. https://code.sololearn.com/cz6LjYdDm3MY/?ref=app
1 Answer
+ 2
do {
System.out.println("What is your favorite ROYGBIV Color?");
System.out.println("Type help for a list of colors?");
String entry5 = input.nextLine().toLowerCase();
if (entry5.equals("help")) {
System.out.println("red, orange, yellow, green, blue, indigo, violet");
}
} while (entry5.equals("help"));
You could also use a not equal to any of the correct available options, just to make sure that a good value is entered.
while (!entry5.equals("red") && !entry5.equals("orange") && !entry5.equals("yellow") && !entry5.equals("green") && !entry5.equals("blue") && !entry5.equals("indigo") && !entry5.equals("violet"));
Instead of using so many if-else statements for the options you'd be better off using a switch statement.