public interface CheckChar {
public static void main(String[] args) {
String str = "zhe ge xiao zi 1991 ni shi ge da huan dai";
checkStr(str);
}
public static void checkStr(String str){
char[] ch = str.toCharArray();
int digital = 0; int character = 0;
int blank = 0; int other = 0;
for(char c:ch){
if(c >='0' && c <='9')
digital++;
else if(c >='a' && c <='z' || c >='A' && c <='Z')
character++;
else if(' '==c)
blank++;
else
other++;
}
System.out.println("数字个数: " + digital);
System.out.println("英文字母个数: " + character);
System.out.println("空格个数: " + blank);
System.out.println("其他字符个数:" + other );
}
}
挑出字符串中的数组、字母、空格个数
最新推荐文章于 2022-10-03 18:31:54 发布