展开全部
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int countNum = 0;//统计数字的个数
int countChar = 0;//统计英文字母的个数
int countSpace = 0;//统计空格的个数
int countOthers = 0;//统计其它早纯字符的个数
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >= '0' && (int) c <= '9') {
countNum++;
} else if ((c >= '局没a' && c <= 'z')||(c >= 'A' && c <= 'Z')) {
countChar++;
} else if (c == ' ') {
countSpace++;
} else{
countOthers++;
}
}
System.out.println("数字个数:"+countNum);
System.out.println("英文字母个数:"+countChar);
System.out.println("空格个数:"+countSpace);
System.out.println("陆腊咐其他字符个数:"+countOthers);
}
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int countNum = 0;//统计数字的个数
int countChar = 0;//统计英文字母的个数
int countSpace = 0;//统计空格的个数
int countOthers = 0;//统计其它早纯字符的个数
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >= '0' && (int) c <= '9') {
countNum++;
} else if ((c >= '局没a' && c <= 'z')||(c >= 'A' && c <= 'Z')) {
countChar++;
} else if (c == ' ') {
countSpace++;
} else{
countOthers++;
}
}
System.out.println("数字个数:"+countNum);
System.out.println("英文字母个数:"+countChar);
System.out.println("空格个数:"+countSpace);
System.out.println("陆腊咐其他字符个数:"+countOthers);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询