public static void main(String[] args) {
//输入字符串,判断里面有多少个大写字母,多少小写字母,多少数字
countVary("fsdfsD4f4sf¥#¥%~&*!@sg9tssfffSFSFS");
}
public static void countVary(String scr){
int countUppper = 0;
int countLower = 0;
int countDigital = 0;
int countOther = 0;
if(scr==null){
throw new RuntimeException("输入字符串不能为空!");
}
StringBuffer buf = new StringBuffer(scr);
char[] scrChar = scr.toCharArray();
for (int i = 0; i < scrChar.length; i++) {
if(scrChar[i]>='a'&&scrChar[i]<='z'){
countLower++;
}
else if(scrChar[i]>='A'&&scrChar[i]<='Z'){
countUppper++;
}
else if (scrChar[i]>='0'&&scrChar[i]<='9'){
countDigital++;
}else{
countOther++;
}
}
System.out.println("字符串:"+scr+"\n大写字母有:"
+countUppper+"个"+"\n小写字母有:"+countLower+"个"+"\n数字有:"
+countDigital+"个"+"\n其他字符有:"+countOther+"个"+"\n共计:"+scr.length()+"个字符");
}