Enter a line of characters to calculate the number of English letters, spaces, numbers, and other characters, and the number of lines

Source: Internet
Author: User

Enter a line of characters to calculate the number of English letters, spaces, numbers, and other characters, and the number of lines
Public class Test2 {


Public static void main (String [] args ){
// TODO Auto-generated method stub
Int abcCount = 0; // number of English letters
Int spaceCount = 0; // Number of Space key
Int numCount = 0; // number of digits
Int otherCount = 0; // number of other characters
String str = "hhhhh666 yh4st66 ****";
Char [] ch = str. toCharArray ();
For (int I = 0; I <ch. length; I ++ ){
If (Character. isLetter (ch [I]) {
// Determine whether it is a letter
AbcCount ++;
} Else if (Character. isDigit (ch [I]) {
// Determine whether the number is correct.
NumCount ++;
} Else if (Character. isSpaceChar (ch [I]) {
// Determine whether the Space key is used
SpaceCount ++;
} Else {
// Other characters are considered if none of the above are true.
OtherCount ++;
}
}
System. out. println ("letter count:" + abcCount );
System. out. println ("number:" + numCount );
System. out. println ("number of spaces:" + spaceCount );
System. out. println ("other characters:" + otherCount );
}


}

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.