华为OJ——输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数

来源:互联网 发布:date json 格式转换 编辑:程序博客网 时间:2024/05/17 02:52

题目描述

输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数。

输入描述:

输入一行字符串,可以有空格

输出描述:

统计其中英文字符,空格字符,数字字符,其他字符的个数

输入例子:
1qazxsw23 edcvfr45tgbn hy67uj m,ki89ol.\\/;p0-=\\][
输出例子:
2631012
<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>




0 0
原创粉丝点击