java-count the number of characters in a string

Source: Internet
Author: User

Package com.day5.test;

public class Test2 {

/**
* @param args
* Requirements: The number of uppercase and lowercase characters, number of occurrences of numeric characters, number of occurrences of other characters in the statistics string
* [Email protected]#$%^

Note if: Else if...else the difference from If...if...if...else
*/
public static void Main (string[] args) {
String s= "[Email protected]#$%^&";
int big=0;
int small=0;
int num=0;
int other=0;
/*for (int i=0;i<s.length (); i++)
{
Char C=s.charat (i);
if (c>= ' A ' &&c<= ' Z ')
big++;
if (c>= ' a ' &&c<= ' Z ')
small++;
if (c>= ' 0 ' &&c<= ' 9 ')//note cannot be written as if (c>=0&&c<=9)
num++;
Else
other++;
}
System.out.println (big);//5
SYSTEM.OUT.PRINTLN (small);//4
SYSTEM.OUT.PRINTLN (num);//6
System.out.println (other);//16
*/
for (int i=0;i<s.length (); i++)
{
Char C=s.charat (i);
if (c>= ' A ' &&c<= ' Z ')
big++;
else if (c>= ' a ' &&c<= ' Z ')
small++;
else if (c>= ' 0 ' &&c<= ' 9 ')//note cannot be written as if (c>=0&&c<=9)
num++;
Else
other++;
}
System.out.println (big);//5
SYSTEM.OUT.PRINTLN (small);//4
SYSTEM.OUT.PRINTLN (num);//6
System.out.println (other);//7
}

}

java-count the number of characters 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.