java

哇哈哈。 2019-06-25 11:29:03
从键盘上输入一个字符串,试分别统计出该字符申中所有数字,大写英文字母、小 写英父宇每以及其他字符的个数并分别输出这些字符 不能用函数,求大佬解答
...全文
33 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
喂文文咯 2019-06-25
  • 打赏
  • 举报
回复
package jeeplus; public class ATest { public static void main(String[] args) { String str ="fafsfavJJLKJL15611/*@"; char[] srChar=str.toCharArray(); Integer aLength = 0; Integer bLength = 0; Integer cLength = 0; for (char c : srChar) { if (c>='a' && c<= 'z') { aLength += 1; System.out.println(c); } } System.out.println("小写字母的长度为"+aLength); for (char c : srChar) { if (c>='A' && c<= 'Z') { System.out.println(c); bLength += 1; } } System.out.println("大写字母的长度为"+bLength); for (char c : srChar) { if (!(c>='a' && c<= 'z') && !(c>='A' && c<= 'Z')) { cLength += 1; System.out.println(c); } } System.out.println("其他字符的长度为"+cLength); } }
weixin_40290083 2019-06-25
  • 打赏
  • 举报
回复
byte [] a = str.tobytes(); for(int i =0;i < a.length;i++){ if(a[i] >= 48 && a[i] <=57){ //数字处理代码 }else if(a[i] >= 64 && a[i] <= 90){ //大写字母处理代码 }else if(a[i] >= 97 && a[i] <= 122){ //小写字母处理代码 } } 思路就是比较ASCII码的值。

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧