Try this,
------------------------------------------------------------
.......... you code..........
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String userText = in.readLine(); // return String from System's default input
stream
// Converting user input from String to int
int userValue = 0; // to be safe from null value
userValue = Integer.parseInt( userText ); // this will throw
NumberFormatException if user have entered something except integer value
// This section will only print if user input was interger
System.out.println(" You entered: " + userValue );
}
catch(NumberFormatException numException) {
System.out.println("Sorry you have not enter an integer, Exception is: " +
numException);
}