Input data from the keyboard

1, reference data types Scanner (Scanner class)

Import Classes in java.util *. ;
 public  class the Input { 

    public  static  void main (String [] args) { 
         Scanner Reader = new new Scanner (the System.in); 
         System.out.println ( "Please enter a positive integer." );
          int = I reader.nextInt (); 
         System.out.println (I); 
         System.out.println ( "Please enter a character string." ); 
         string S = reader.next (); 
         System.out.println (S) ; 
         } 
}

2、BufferedReader类

 

Import the java.io. * ;
 public  class the Input { 

    public  static  void main (String [] args) throws IOException 
    { 
        String STR; 
        the BufferedReader buf = new new the BufferedReader ( new new the InputStreamReader (the System.in)); 
        System.out.println ( "Please enter a positive integer " ); 
        STR = buf.readLine ();
         int I = the Integer.parseInt (STR); 
        System.out.println ( " digital input of "+ I); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/zhai1997/p/11257872.html