import java.util.Scanner;
public class Test5
{
public static void main(String [] args)
{
//1.先用四个变量分别记录要统计的字符
int integer =0;
int english =0;
int space = 0;
int other = 0;
char [] ch =null ;
Scanner sc =new Scanner(System.in);
String s =sc.nextLine();
ch = s.toCharArray();
//2.把字符串转化成字符数组,然后遍历
for (int x =0;x<ch.length;x++ )
{
//3.判断数组中的每一个字符,并记录数量
if(ch[x]>='0'&&ch[x]<='9'){
integer++;
}
else if(ch[x]>='a'&&ch[x]<='z'||ch[x]>='A'&&ch[x]<='Z'){
english++;
}
else if(ch[x]==' '){
space++;
}
else {
other++;
}
}
//4.输出数量
System.out.println("数字"+integer+"个,英文字母"+english+"个,空格"+space+"个,其他"+other+"个");
}
}
| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |