I am trying to have my user input not crash my program by restricting what the user can input such as:
String choose = "";
System.out.println("Test if input is an integer. Type 'quit' to exit.");
System.out.print("Type an integer: ");
Scanner sc=new Scanner(System.in);
choose = sc.nextLine();
while (!(choose.equalsIgnoreCase("quit"))) {
int d = 0;
try {
d = Integer.parseInt(choose);
if (!(d > 0 && d < 31)) {
System.out.println("Being between 1-30");
} else {
System.out.println("Input is an integer.");
}
} catch (NumberFormatException nfe) {
System.out.println("Enter only int");
}
System.out.print("Type an integer to test again or 'quit' to exit: ");
sc = new Scanner(System.in);
choose = sc.nextLine();
}
sc.close();
System.out.print("Program ends.");