I am noob, so I apologize if I ask a stupid question. I ask the user to enter a numerical value. If the value is less than 12 or not a numerical value, such as a number, I want it to request them for another input. When a value of at least 12 is entered, I want this value to be assigned to a variable with a name creditUnits;
When I ask for the initial prompt, my program will catch it, if the entered value is not numeric, it will ask the user to enter "Valid number:". The while loop seems to work well.
I had a problem with the second cycle, where it is assumed that any number entered in it will be less than 12. It will ask the user to enter a value greater than 11. The problem I am facing is at this moment if the user enters any value at this moment, the program is just sitting there. Any help would be appreciated, and I apologize in advance for the carelessness of my code:
System.out.print("Enter the credits you will take each term: ");
while (!in.hasNextDouble()){
System.out.print("Enter a valid number: ");
in.next();
}
creditUnits = in.nextDouble();
if (creditUnits < 12){
System.out.print("Enter a number greater than 11: ");
in.next();
}
creditUnits = in.nextDouble();
System.out.println("You will be taking " + creditUnits + " credits per term.");
source
share