日期:2014-05-20 浏览次数:20581 次
public class StringTest { public static void main(String[] args) { String a = "jsldfj#$#%r_343545jlkj&&^&^%^"; int uCount = 0, lCount = 0, oCount = 0; /*for(int i=0; i<a.length(); i++) { char c = a.charAt(i); if(c >= 'a' && c <= 'z') { lCount ++; }else if(c >= 'A' && c <= 'Z') { uCount ++; }else{ oCount ++; } }*/ for(int i= 0;i<a.length(); i++) { char c = a.charAt(i); if(Character.isLowerCase(c)) { lCount ++; } else if(Character.isUpperCase(c)) { uCount ++; } else { oCount ++; } } System.out.println("大写字母个数是: "+uCount+"小写字母个数是: "+lCount+"其他字符个数是: "+oCount); } }