I want to scan in an integer and put it in a while loop so that if an invalid entry is entered the program will ask to enter another integer but when I run this it won't allow me to enter and new integer and just prints invalid entry multiple times.
do {
System.out.println("Maximum number of Students:");
if(input.hasNextInt()) {
maxstudents = input.nextInt();
if (maxstudents > 0) {
break;
}
} else {
System.out.println("Invalid entry");
}
} while(true);