Calculates the number of uppercase, lowercase, special characters, numbers in a string

Source: Internet
Author: User

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

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.