java code to input an integer number only

Solutions on MaxInterview for java code to input an integer number only by the best coders in the world

showing results for - "java code to input an integer number only"
Gael
03 Jan 2017
1static Scanner sc = new Scanner(System.in);
2    public static int Input(String mess){
3        
4        int x=0;
5        while(true){
6            try{
7                System.out.println(mess);
8                x= Integer.parseInt(sc.nextLine().trim());
9                break;
10            }
11            catch(Exception e){
12                System.out.println("Error!Pls input integer number.");
13                
14            }
15        }    
16        return x;
17    }
18public static void main(String[] args){
19  	int Input=Input("Enter integer:");