1 Public classTest_123_test {2 Public Static voidMain (string[] args) {3String str = "[Email protected]#¥%......&";4 intbigs = 0;//record the number of uppercase letters5 intSmalls = 0;//record the number of lowercase letters6 intothers = 0;//record the number of other characters7 intShuzi = 0;8 System.out.println (Str.length ());9 for(inti = 0; I < str.length (); i++) {Ten Charstr_1 = Str.charat (i);//remove each character in turn One if(' A ' <= str_1 && ' Z ' >=str_1) { Abigs++;//Record capital letters -}Else if(' A ' <= str_1 && ' z ' >=str_1) { -smalls++; the}Else if(Character.isdigit (str_1)) { -shuzi++; -}Else { -others++; + } - } +System.out.println ("Number of uppercase letters: =" +bigs); ASystem.out.println ("Number of lowercase letters: =" +Smalls); atSystem.out.println ("Number of special characters: =" +others); -System.out.println ("number of numbers: =" +Shuzi); -System.out.println ("a common character: =" +str.length ()); - } -}
Description: A random string that calculates the number of characters in each class
* For example: abcde*&^% $ABCDE 123456 The number of uppercase letters, lowercase letters, special characters, numbers is calculated
*
* Solve the idea: can be solved by Ascci code or through the method of character method directly to select, but the first must be a string of characters to be split to
*
Calculates the number of uppercase, lowercase, special characters, numbers in a string