Eclipse Console input

Source: Internet
Author: User

Console input Statements


To use the Scanner class, the import Java.util.Scanner should be imported first;

The object is then established Scanner sc = new Scanner (system.in);

You can then receive a variety of data types from the console input.

Like what:

String s = sc.next ();//Receive console input for various data types

String s = sc.nextline ();//Receive console input for various data types

The difference between next and Nextline is that the former receives a string up to the first space, and the latter receives a string that can contain a space, until the carriage return.

Double d = sc.nextdouble ();

If you want to enter a character, you can take advantage of the Charat (index) method of the string.

For example, char ch = sc.next (). charAt (0);

You can also write directly: char ch = new Scanner (system.in). Next (). charAt (0);


Integral type: int a=new Scanner (system.in). Nextint ();

Floating point: Float b=new Scanner (system.in). Nextfloat ();

Floating point: Double b=new Scanner (system.in). nextdouble ();

String: String S=new Scanner (system.in). Next ();

String s=new Scanner (system.in). nextline ();

Ways to get characters:

char ch = new Scanner (system.in). Next (). charAt (0);


Eclipse Console input

Related Article

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.