Java self-injection three-entry

Source: Internet
Author: User

Since the recent study of the content of the actual operation is more, so the new notes to use the code as the main bar!

The main content of this back is input, Java mainly uses scanner class and BufferedReader. Overall not difficult, but some of the details can be summarized, see the code:

Import Java.io.*;import Java.util.scanner;public class Iotest{public static void Main (string[] args) throws exception{// Scanner provides a variety of constructors, different constructors can accept files, input streams, strings as data sources//used to extract parse out basic type values and string values//here system.in represents keyboard input Scanner sc = new Scanner ( system.in);//The default is a space, using the regular table Sc.usedelimiter ("\ n"),//hasnextxxx (), XXX does not write, default feel string//has the next item returns TRUE, but if there is no next item does not necessarily return false, It is also possible to be blocked here for blocking while (Sc.hasnext ()) {//output input string next = Sc.next (); if (Next.equals ("exit") break; SYSTEM.OUT.PRINTLN ("Keyboard input content is" + next);} String s = "Hello cer"; Scanner ss = new Scanner (s);//return here Falsewhile (Ss.hasnext ()) {System.out.println ("The contents of the string are:" +ss.next ());} Always read string object BufferedReader br = new BufferedReader (new InputStreamReader (system.in)); String line = Null;while ((line = Br.readline ()) = null) {System.out.println ("User keyboard input is:" + line);}}

Output Result:

$ Java iotest
Cer
The content of the keyboard input is a CER
Exit
The contents of the string are: Hello
The contents of the string are: CER
Test String
User keyboard input is: Test String


As the gaze writes, the scanner Hasnext () of the keyboard input will be more useful when there is no next token in the block's character.

Java self-injection three-entry

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.