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