题目描述
输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数。
输入描述:
输入一行字符串,可以有空格
输出描述:
统计其中英文字符,空格字符,数字字符,其他字符的个数
输入例子:
1qazxsw23 edcvfr45tgbn hy67uj m,ki89ol.\\/;p0-=\\][
输出例子:
26
3
10
12
- <span style="font-size:18px;">import java.util.*;
- public class Main {
-
- public static void main(String[] args) {
-
- Scanner scan=new Scanner(System.in);
- int eng=0,space=0,num=0,other=0;
- while(scan.hasNext())
- {
- char[] chars=scan.nextLine().toCharArray();
- for(char ch:chars){
- if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
- {
- eng++;
- }else if(ch==' '){
- space++;
- }else if(ch>='0'&&ch<='9'){
- num++;
- }else{
- other++;
- }
- }
- System.out.println(eng+"\n"+space+"\n"+num+"\n"+other);
- }
- }
- }</span>