package com.kevin.test;
public class Demo5_Test {
public static void main(String[] args) {
String s1 = "sjdfsdjflk;sadjfkl;sdjfkASADsdfds SDF123123@@@SDFSDFSDsdfsdfA";
int count1=0;
int count2=0;
int count3=0;
int count4 = 0;
int count5 = 0;
for (int i = 0; i < s1.length(); i++) {
char c = s1.charAt(i);
if(c >= 'a' && c<='z'){
count1++;
}else if(c >= 'A' && c<='Z'){
count2++;
}else if(c >= '0' &&c<='9'){
count3++;
}else if(c == ' '){
count4++;
}else{
count5++;
}
}
System.out.println("找到小写字符"+count1+"次"+'\n'+"找到大写字符"+count2+"次"+'\n'+"找到数字字符"+count3+"次"+'\n'+"找到空格字符"+count4+"次"+'\n'+"找到其他符号字符"+count5+"次");
}
}
|
|