In my program I want an integer input by the user. I want an error message to be show when user inputs a value which is not an integer. And How can I do this in loop. i am just a beginner please help me.
//code that i already try
Scanner input = new Scanner(System.in);
int age;
String AGE ;
System.out.print("\nEnter Age : ");
AGE = input.nextLine();
try{
age = Integer.parseInt(AGE);
}catch (NumberFormatException ex){
System.out.print("Invalid input " + AGE + " is not a number");
}