public class Test {
public static void main(String[] args) {
String s = "48WERSFas!@#";
//String s = "23479odurqjPOWUER00*)*&)(#084234-9LRWEJRLJ5R2)*q#)*puFOURoupPU_(*";
int countNum = 0;
int countUpperCase = 0;
int countLowerCase = 0;
int countOther = 0;
for(int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if(c >= 'A' && c <= 'Z') {
countUpperCase ++;
} else if(c >= 'a' && c <= 'z') {
countLowerCase ++;
} else if(c >= '0' && c <= '9'){
countNum ++;
} else {
countOther ++;
}
}
System.out.println(countNum);
System.out.println(countUpperCase);
System.out.println(countLowerCase);
System.out.println(countOther);
}
}
public class Test { public static void main(String[] args) { //String s = "48WERSFas!@#"; String s = "23479odurqjPOWUER00*)*&)(#084234-9LRWEJRLJ5R2)*q#)*puFOURoupPU_(*"; int countNum = 0; int countUpperCase = 0; int countLowerCase = 0; int countOther = 0; char[] sc = new char[s.length()]; for(int i = 0; i < s.length(); i++) { sc[i] = s.charAt(i); if(sc[i] >= 65 && sc[i] <= 90) { countUpperCase ++; } else if(sc[i] >= 87 && sc[i] <= 122) { countLowerCase ++; } else if(sc[i] >= 48 && sc[i] <= 57){ countNum ++; } else { countOther ++; } } System.out.println(countNum); System.out.println(countUpperCase); System.out.println(countLowerCase); System.out.println(countOther); } } //还有一种方法
转载于:https://www.cnblogs.com/spring4/archive/2012/04/30/2483674.html