1. The Character class wraps the value of a basic type char in an object
In addition, the class provides several methods to determine the categories of characters (lowercase letters, numbers, and so on) and to convert characters from uppercase to lowercase, and vice versa
Construction Method:
Character (char value)
1 Public classCharacterdemo {2 Public Static voidMain (string[] args) {3 //Creating Objects4 //Character ch = new Character ((char));5Character ch =NewCharacter (' a ');6SYSTEM.OUT.PRINTLN ("Ch:" +ch);7 }8}
2, character of several methods:
1. public static Boolean isuppercase (char ch): Determines whether the given character is uppercase characters
2. public static Boolean islowercase (char ch): Determines whether the given character is lowercase characters
3. public static Boolean isdigit (char ch): Determines whether a given character is a numeric character
4, public static char touppercase (char ch): Converts the given character to uppercase characters
5, public static char tolowercase (char ch): Converts the given character to lowercase characters
3. Count the number of uppercase characters, lowercase alphabetic characters, and numeric characters that appear in a string. (No other characters are considered)
Analysis:
A, keyboard input string
B, define 3 int variables: smallcount, Bigcount, Numbercount
C, convert the string to an array, and traverse the judgment
A, the characters are lowercase letters: smllcount++
b, the character is uppercase: bigcount++
C, the character is a number: numbercount++
D, Output results
E, written Method:
A, return type: void prints the result directly
B, parameter list: string str
1 ImportJava.util.Scanner;2 Public classCharacterTest1 {3 4 Public Static voidMain (string[] args) {5 //Create keyboard Entry6Scanner sc =NewScanner (system.in);7System.out.println ("Please enter string:");8String str =sc.nextline ();9 Ten //Calling Methods One choose (str); A } - - //Defining Methods the Public Static voidChoose (String str) { - //Define 3 variables - intSmallcount = 0; - intBigcount = 0; + intNumbercount = 0; - //Convert a string to an array + Char[] ch =Str.tochararray (); A //iterating and judging an array at for(intx = 0; x < ch.length; X + +){ - //Public Static Boolean islowercase (char ch): Determines whether the given character is lowercase characters - if(Character.islowercase (ch[x])) { -Smallcount + +; - } - Else if(Character.isuppercase (ch[x])) { inBigcount + +; - } to Else if(Character.isdigit (ch[x])) { +Numbercount + +; - } the } *System.out.println ("The lowercase letters in a string have a total of" +smallcount+ "); $SYSTEM.OUT.PRINTLN ("Uppercase letters in a string have a total of" +bigcount+ ");Panax NotoginsengSystem.out.println ("The number in the string has a total of" +numbercount+ "); - } the +}
Wrapper class for Java 13-6 char character