Basically, what I want my code to do is if the user inputs anything besides "sum, quit, max, min" I want the program to loop back and ask the user the options again. I tried using a while-loop but I can't add multiple String objects within it. I'm stuck on what to do. (Also, I used if-statements instead of while so it won't continually repeat and be stuck.)
EDIT: thank you for the help! I used a while(true), break statements, and a continue at the end and it seems to work!
public static void main (String [] args){
System.out.println("Enter the option sum, max, min:");
Scanner input = new Scanner (System.in);
user = input.nextLine();
double [] y = theArray();
if (user.equals("sum")){
//do something
}
else if (user.equals("max")){
//do something
}
else if (user.equals("min")){
//do something
}
else if (user.equals("Quit")){
//do something
}
}
}
whileinfinite loop and break it when the condition is met.while(user.equals("quit", "sum")){you can saywhile(user.equals("quit") || user.equals("sum")){, and add more||'s (Or's) as needed for anything else. If that logic makes more sense to you than the break or the recursion answers below, give it a try.