在java中,对指定字符串,进行大小写字母 以及数字的统计:
public class StringTest{
public static void main(String[] args){
getCount("A%A3eBr1FFy");
}
/*
获取指定字符串中,大写字母,小写字母,数字的个数
思想:
1.计数器,定义int变量,满足一个条件++
2.遍历字符串,长度方法length()+charAt()遍历
3.字符判断是大写 小写 还是数字
*/
public static void getCount(String str){
//定义三个变量
int upper = 0;
int lower = 0;
int dight = 0;
//对字符串遍历
for(int i = 0; i < str.length();i++){
//String方法charAt,索引,获取字符
char c = str.charAt(i);
//利用编码表65 - 90 ; 97 - 122 ; 48 - 57
if(c >= 65 && c <= 90 ){
upper++;
}
else if(c >= 97 && c <= 122){
lower++;
}
else if(c >= 48 && c <= 57){
dight++;
}
}
System.out.println(upper);
System.out.println(lower);
System.out.println(dight);
}
}