Java calculates the number of uppercase/lowercase letters and non-English letters in a string.

Source: Internet
Author: User

 

//One idea:

//Extract each character from the string, compare each character cyclically, and record the corresponding number of characters with three variables.

 

 

 

// The second silly way of thinking: first define 26 upper and lower case letters, and then search by index

 

// Method 3: Use the islowercase () and isuppercase () Methods of the character packaging class:

 

 Summary:

1. Java is very powerful, and it encapsulates some common methods. On the basis of understanding, it is of course easy-to-use.

2. It is very important to frequently check Java API documentation, a giant of Java.

3. The first two ideas contain clever ideas, which are of great help to extend thinking. If you do not know Java, you can solve it with the knowledge you have learned.

Common Mistakes

1.Note:A [I]<='Z'WrittenA [I]<="Z"The following error occurs: Operator<=Cannot be usedChar, java. Lang. String

Because double quotation marks indicate strings (StringType). Single quotes indicate characters (CharType ).

2. If the length () method I <J. Length () is written as I <jlength, an error is returned.

 

 

 

 

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.