Get a character from the keyboard

Source: Internet
Author: User

Problem: switch is used to convert the lowercase char type to uppercase. Only the output "other" of A, B, C, D, E. Is converted ".

Import Java. util. imports; import Java. io. ioexception;/* receives a character from the console and prints it out. // although this method obtains the input character from the keyboard. in. read () can only be obtained for one character. At the same time, the retrieved variable type can only be char. When we enter a number and want to obtain an integer variable, we have to modify the variable type, which makes it quite troublesome. */Class test5 {public static void main (string [] ARGs) throws ioexception {// S = new evaluate (system. in); // string c = S. next (); char c = (char) system. in. read (); Switch (c) {Case 'A': system. out. println ("A"); break; Case 'B': system. out. println ("B"); break; Case 'C': system. out. println ("C"); break; Case 'D': system. out. println ("D"); break; Case 'E': system. out. println ("e"); break; default: system. out. println ("other"); break ;}}}


This article is from the "First day of course" blog, please be sure to keep this source http://5453607.blog.51cto.com/5443607/1529887

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.