Java Basics-Letter case Conversion

Source: Internet
Author: User

Case:

  Requires a letter from the console to be received by the user, if the letter is lowercase, converted to uppercase, if the letter is uppercase, converted to lowercase, can only enter letters, if it is another value, the data is wrong!

Implementation code:

ImportJava.util.Scanner;/*** Common Letter Case Conversion * Principle: * Character Char uses a Unicode encoded 16-bit character type, which represents a range of 0-65536. The standard 8-bit ASCII character set is a subset of Unicode * with a value range of 0-127. There's a difference between uppercase and lowercase letters.@authorAdministration **/ Public classWordchange { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); System.out.println ("Please enter the letters you need to convert:"); Charc = Input.next (). CharAt (0);    Change (c); }    Private Static voidChangeCharc) {//If you enter uppercase, +32 will get lowercase        if(c>= ' A ' && c<= ' Z ') {C+=32; System.out.println ("The capital Letter you entered" + (Char) (c-32) + "converted to" +c); }Else if(c>= ' A ' && c<= ' z ') {//if the input is lowercase,-32 can be caseC-=32; System.out.println ("The lowercase letter you entered" + (Char) (c+32) + "converted to" +c); }Else{System.out.println ("The character entered is wrong!! "); }    }}

Principle Analysis:

  the character Char takes a Unicode-encoded 16-bit character type, which represents a range of 0-65536. The standard 8-bit ASCII character set is a subset of Unicode with a value range of 0-127. There's a difference between uppercase and lowercase letters.

Java Basics-Letter case Conversion

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.