I'm a beginner in Java, so I had a question on this I'm trying to create a simple code in which I'm done with it, just I wanted to know how do you set up an infinitely asking question that the user can input? The one I have right now does an infinite loop, which is not helpful...
import java.util.Scanner;
public class Logical_Operators {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
//this is a conditional scenario, where only boys above the age of 18 can enter
//and only girls equal to or over the age of 20
String gender, boy, girl, response;
int age;
System.out.println("Welcome to the party! Would you like to enter?");
response = input.nextLine();
while(!response.equals("yes") && !response.equals("no")) {
System.out.println("Please say Yes or No");
}
{
if(response.equals("yes")) {
System.out.println("What gender are you? Type boy or girl.");
gender = input.nextLine();
System.out.println("What about your age?");
age = input.nextInt();
if(gender.equals("boy") && age >= 18) {
System.out.println("You can enter, Welcome!");
}
else if(gender.equals("girl") && age >= 20) {
System.out.println("You can enter, Welcome!"); }
else { System.out.println("Sorry, you may not enter because you don't meet the age requirements"); }
}
else if(!(response.equals("yes")||response.equals("no"))) {
System.out.println("Please say Yes or No");
}
else {
System.out.println("Bye, hope to see you again!");
}
System.exit(1);
}
}
}