[Java Study Notes] read and write on the console

Source: Internet
Author: User

author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

Import Java. io. console; public class consolelogin {public static void main (string Arg []) {console con; con = system. console (); If (con = NULL) {system. out. println ("no console available. "); return;} string name = con. readline ("name:"); char PW [] = con. readpassword ("Password:"); string Password = new string (PW); system. out. println ("the login name is" + name + "and the pass word is" + password );}} ================================== import Java. io. console; public class consoleoutput {public static void main (string Arg []) {console con; con = system. console (); If (con = NULL) {system. out. println ("no console available. "); return;} int value = 31520; con. printf ("The Number % d as hexidecimal is % 4x/N", value, value) ;}note that the Read and Write methods of the console class are synchronized, and the console may not exist (of course, if you use cmd or shell, it is recommended that you use flush to refresh the display .)

 

Author: gnuhpc

Source: http://www.cnblogs.com/gnuhpc/

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.