统计字符串中数字,字母,大写字母的个数

public class Test5 {

public static void main(String[] args) {
String str = "kDLs4f0565v6K";
tod(str);
System.out.println("小写字母的个数是"+tod(str)[0]);
System.out.println("大写字母的个数是"+tod(str)[1]);
System.out.println("数字的个数是"+tod(str)[2]);
}
public static int[] tod(String str){
int[] s = new int[3];
for(int i=0;i<str.length();i++){
char ch = str.charAt(i);
if(ch>'a'&&ch<'z'){
s[0]++;
}else if(ch>'A'&&ch<'Z'){
s[1]++;
}else if(ch>'0'&&ch<'9'){
s[2]++;
}
}
return s;
}
}

posted on 2017-11-29 14:07  acaca  阅读(833)  评论(0)    收藏  举报