Answers for "java code to input an integer number only"

1

java code to input an integer number only

static Scanner sc = new Scanner(System.in);
    public static int Input(String mess){
        
        int x=0;
        while(true){
            try{
                System.out.println(mess);
                x= Integer.parseInt(sc.nextLine().trim());
                break;
            }
            catch(Exception e){
                System.out.println("Error!Pls input integer number.");
                
            }
        }    
        return x;
    }
public static void main(String[] args){
  	int Input=Input("Enter integer:");
Posted by: Guest on September-14-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language