统计大写字母个数
2015-08-18 17:15
183 查看
import java.util.Scanner; public class Main{ public static void main(String[]args){ Scanner scanner = new Scanner(System.in); String s=scanner.nextLine(); if (s.isEmpty()) { System.out.println(0); }else{ int no=0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i)>=65 && s.charAt(i)<=90) { no++; } } System.out.println(no); } } }
还有一个方法,个人认为没问题,但是在
oj上是错误的。
import java.util.Scanner; public class GetUpperCaseNum { /** * * 找出给定字符串中大写字符(即'A'-'Z')的个数 */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); String num = scan.nextLine(); int count = 0; if(num.isEmpty()) System.out.println(0); char[] ch = num.toCharArray(); for (char c : ch) { if(Character.isUpperCase(c)) count++; } System.out.println(count); } }
相关文章推荐
- java 连接oracle数据库
- 【转载】HBase 数据库检索性能优化策略
- Java 发送邮件
- JSTL中的fmt
- 手动编译安装lamp 遇到的问题与解决方法
- Nginx配置文件详细说明
- IOS开发第三方语音-微信语音
- assert函数用法总结
- hdoj 1873 看病要排队
- js笔试题
- 即时通讯研究学习
- eclipse & as 项目编码修改
- gdb: info breakpoints显示所有断点
- SVN不能提交,让更新,更新完还是不能提交的解决办法
- python list遍历时删除元素的推荐做法
- 我的日记
- 预处理
- Android内存优化
- HDU 5402 Travelling Salesman Problem
- HDOJ 2108 Shape of HDU(凸包问题)