会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
spring学习笔记
java例程练习(统计字母数字等字符的个数)
public class Test { public static void main(String[] args) { //String s = "48WERSFas!@#"; String s = "23479odurqjPOWUER00*)*&)(#084234-9LRWEJRLJ5R2)*q#)*puFOURoupPU_(*"; int countNum = 0; int countUpperCase = 0; int countLowerCase = 0; int countOther = 0; char[] sc = new char[s.length()]; for(int i = 0; i < s.length(); i++) { sc[i] = s.charAt(i); if(sc[i] >= 65 && sc[i] <= 90) { countUpperCase ++; } else if(sc[i] >= 87 && sc[i] <= 122) { countLowerCase ++; } else if(sc[i] >= 48 && sc[i] <= 57){ countNum ++; } else { countOther ++; } } System.out.println(countNum); System.out.println(countUpperCase); System.out.println(countLowerCase); System.out.println(countOther); } }
//还有一种方法
<pre name="code" class="java">public class Test { public static void main(String[] args) { String s = "48WERSFas!@#"; //String s = "23479odurqjPOWUER00*)*&)(#084234-9LRWEJRLJ5R2)*q#)*puFOURoupPU_(*"; int countNum = 0; int countUpperCase = 0; int countLowerCase = 0; int countOther = 0; for(int i = 0; i < s.length(); i++) { char c = s.charAt(i); if(c >= 'A' && c <= 'Z') { countUpperCase ++; } else if(c >= 'a' && c <= 'z') { countLowerCase ++; } else if(c >= '0' && c <= '9'){ countNum ++; } else { countOther ++; } } System.out.println(countNum); System.out.println(countUpperCase); System.out.println(countLowerCase); System.out.println(countOther); } }
posted on
2012-04-30 14:17
spring学习笔记
阅读(
255
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
博客园
首页
联系
订阅
管理
公告