java-Console accepts user input data method

Source: Internet
Author: User

1 The package console accepts input;2 3 import Java.io.BufferedReader;4 import java.io.IOException;5 import Java.io.InputStream;6 import Java.io.InputStreamReader;7 import Java.nio.Buffer;8 import Java.util.Scanner;9 Ten  Public classInputcode { One      Public Static voidMain (string[] args) throws IOException { A         /* - * Methods in the Scanner class - * Perfect the          */ -Scanner input =NewScanner (System.inch); -System. out. println ("Please input your name"); -String name=input.nextline (); +System. out. println (name); -         /* + * Cons: Only one character entered by the user can be accepted A          */ atSystem. out. println ("Enter your name"); -         CharName1 =0; -         Try { -             //the Read () method in InputStream puts the next character back into the input stream -Name1 = (Char) System.inch. read (); -}Catch(IOException e) { in e.printstacktrace (); -         } toSystem. out. println (name1); +         /* - * InputStreamReader and BufferedReader methods the * Advantages: can get string * * Cons: Get int or string people need strong turn $          */Panax Notoginseng         //Typically, every read request made by reader results in a corresponding read request to the underlying character or byte stream. Therefore, it is recommended to use BufferedReader -         //wraps all of its read () operations with potentially expensive Reader (such as FileReader and InputStreamReader). For example, the         //BufferedReader in= New BufferedReader (New FileReader ("foo.in")); +System. out. println ("Enter your name"); AInputStreamReader input1=NewInputStreamReader (System.inch); theBufferedReaderinch=NewBufferedReader (INPUT1); +String name2=inch. ReadLine (); -System. out. println (name2); $     } $}

java-Console accepts user input data method

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.