Java method for reading numbers or strings in a console _java

Source: Internet
Author: User

in Java , int a = System.in.read (); This sentence reads a character and then returns the ASCII of the corresponding character,

For example, the console enters 123, reads only one character 1, the corresponding ASCII is 49, the output is 49, the input ABC reads a, the corresponding ASCII is 97, then the output is 97;

Scanner sc = new Scanner (system.in)

int n = sc.nextint (); Read a number from the console.

String c = Sc.next ();//reading strings from console

The above is a small set for everyone to bring the Java in the console to read numbers or strings of the whole content of the method, I hope to help you, a lot of support cloud Habitat Community ~

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.