Please help me understand why the while loop prompts the statement "enter am or pm" twice. I need it to ask only once and wait for an input. Only if the input in invalid, should the loop execute again.
System.out.println(" ");
int startHour=0;
boolean validAnswerOne=false;
while (validAnswerOne == false){
System.out.println("Enter the starting hour: ");
startHour = input.nextInt();
if (startHour<=12){
validAnswerOne=true;
}
}
String validAnswerTwo = "False";
while (validAnswerTwo.equals("False"))
{
System.out.println("Enter am or pm: ");
String time = input.nextLine();
time = time.toLowerCase();
if (time.equals("am") || time.equals("pm"))
{
validAnswerTwo="True";
}
}