【计蒜客系列】挑战难题374:统计个数(课后)
2015-09-24 09:15
423 查看
题目来源:计蒜客
输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
一行字符
统计值
样例1
输入:
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
输出:
23 16 2 4
输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
一行字符
统计值
样例1
输入:
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
输出:
23 16 2 4
import java.util.*; public class Main { public static void main(String args[]) throws Exception { Scanner scanner = new Scanner(System.in); String str = scanner.nextLine(); if(str.length() != 0){ countNum(str); }else{ System.out.println("error"); } } public static void countNum(String src){ char[] cha = src.toCharArray(); int eng = 0; int blank = 0; int num = 0; int other = 0; for(int i = 0;i < cha.length;i++){ if((cha[i] >= 'a' && cha[i] <= 'z') || (cha[i] >= 'A' && cha[i] <= 'Z')){ eng++; }else if(cha[i] == ' '){ blank++; }else if(cha[i] >= '0' && cha[i] <= '9'){ num++; }else{ other++; } } System.out.println(eng + " " + num + " " + blank + " " + other); } }
相关文章推荐
- android:DDMS查看Threads
- 轉載:90%家长后悔太晚读到此文
- Objective-C---2---初始化、便利构造器
- 纯CSS写带边框的三角形
- Swift控制转移语句
- 总结sql语句
- 【计蒜客系列】挑战难题373:加密(课后)
- android 语言识别
- 谷歌卫星地图导出MBTile离线包及应用教程
- 你知道老总难题是什么吗?
- opencv中的一些矩阵的简单操作函数
- IOS 设置应用图标
- 【题解】 2015 ACM/ICPC Asia Regional Shenyang Online (3+1)
- CoordinatorLayout-带图片伸缩工具栏
- C# 加密算法
- CentOS 7 下yum安装xtrabackup备份工具
- NIS & Kerberos配置
- 异常:Project configuration is not up-to-date with pom.xml解决方案
- UI 布局(WPF)
- MP3文件格式解析