The static method below reads only int values using BufferedReader (stdin) and throws Exception if int is not read.
public static int readInt () {
while (true) {
try{
String line = stdin.readLine();
int value = Integer.parseInt(line);
return value;
} catch(java.lang.NumberFormatException e){
;
} catch(IOException e){
;
}
}
} // end readInt ()