I basically want the following while loop to check if the input is an integer. It cannot contain decimals because it is pointing to an array. If the value entered is a decim
A small modification to your program solves the problem
System.out.print("Enter month (valid values are from 1 to 12): ");
Scanner monthScan = new Scanner(System.in);
int monthInput = monthScan.nextInt();
// If the month input is below 1 or greater than 12, prompt for another value
while((monthInput<1 || monthInput>12) )
{
System.out.print("Invalid value! Enter month (valid values are from 1 to 12): ");
monthInput = monthScan.nextInt();
}
System.out.println("I am here");
Output:
Enter month (valid values are from 1 to 12): -5
Invalid value! Enter month (valid values are from 1 to 12): -5
Invalid value! Enter month (valid values are from 1 to 12): -2
Invalid value! Enter month (valid values are from 1 to 12): 5
I am here
Hope this helps you.