Import Java.io.BufferedReader; Import java.io.IOException; Import Java.io.InputStreamReader; Import Java.util.Scanner; public class MainClass { public static void Method1 ()  &N Bsp { //Use Scanner scanner scanner=new S Canner (system.in); system.out.print ("Please input a number:"); int num=scanner.nextint (); //Get integer value //string temp = Scanner.next ();//Get String value  SYSTEM.OUT.PRINTLN ("The number you are:" +num); system.out.println ("----------------------------"); system.out.print ("Please input some character:"); string Str=scanner.Next (); //Get String value  SYSTEM.OUT.PRINTLN ("The string you are:" +STR);  } public static void Method2 ( ) { //using BufferedReader &NBSP ; try { bufferedreader R Eader=new BufferedReader (New InputStreamReader (system.in)); system.out.print ("Please input a number:"); string str=reader.readline (); //get string  SYSTEM.OUT.PRINTLN ("The number you are:" +STR);  } catch (IOException e) {  &NB Sp &Nbsp;e.printstacktrace (); } }
public static void Method3 () {//define byte array length, and do exception handling, read current bytes byte[] buffer= new Byte[len]; try {System.in.read (buffer, 0, Len); catch (Exception e) {} String str = newstring (buffer); System.out.println (str); } }
PostScript: The second method uses the ReadLine () method to return a value of type string. If you want to get an int or float type, you need a write-type conversion function on the row conversion
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.