笔试题——编写java程序:输入一个字符串,判断有几个英文字母,有几个数字,有几个其它的字符
2015-10-10 22:08
1016 查看
public static void main(String[] args) { int count_abc=0,count_num=0,count_oth=0; //输入一串数 Scanner scan=new Scanner(System.in); String str = scan.next(); char[] chars = str.toCharArray(); //判断每个字符 for(int i = 0;i<chars.length;i++){ if((chars[i]>=65&&chars[i]<=90)||(chars[i]>=97&&chars[i]<=122)){ count_abc++; }else if(chars[i]>=48&&chars[i]<=57){ count_num++; }else{ count_oth++; } } System.out.println("字母有:"+count_abc+"个"); System.out.println("数字有:"+count_num+"个"); System.out.println("其他的有:"+count_oth+"个"); } public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); String getMess=scan.nextLine(); int zm=0; int num=0; int other=0; char [] ch = getMess.toCharArray(); for(int i=0;i<ch.length;i++){ if((ch[i]>='a' && ch[i]<='z') || (ch[i]>='A' && ch[i]<='Z')){ zm=zm+1; }else if(ch[i]>47 && ch[i]<58){ num=num+1; }else{ other=other+1; } } System.out.println("字母:"+zm); System.out.println("数字:"+num); System.out.println("其它:"+other); }
相关文章推荐
- 离线安装eclipse的Maven插件
- JavaBean
- Java反射机制
- Java异常分析
- Java 正则表达式学习总结和一些小例子
- 银联在线 网关支付 (JAVA版)
- 银联在线 网关支付 (JAVA版)
- 安装Eclipse Maven插件的几种方法
- 记录spring切面代码,
- java8笔记一
- eclipse workspace出错而导致启动不了
- JAVA_SE基础——41.instanceof关键字(运算符)
- Spring常用注解
- java快速教程系列(转载于博客园--作者:vamei)
- Android项目从Eclipse迁移到Android Studio的过程和一些问题汇总
- 第一阶段考核中的JAVA简答题
- Struts2中配置默认Action
- struts 2配置文件的包继承
- JAVA项目出现红色叹号
- struts 2配置两种的结果