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