java例程练习(统计字母数字等字符的个数)
2012-04-30 14:17
357 查看
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); } }
//还有一种方法
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);}}
相关文章推荐
- java例程练习(统计字母数字等字符的个数)
- java例程练习(统计字母数字等字符的个数)
- java循环练习:输入一个字符串,统计该字符串中分别包含多少个数字,多少个字母,多少个其他字符
- java统计英文字母、空格、数字和其它字符的数目
- [Java]练习题007: 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- java统计英文字母、空格、数字和其它字符的数目
- java面试题---统计中含有字母数字中的最大字符
- [Java]练习题007: 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- 第九周练习--统计出其中英文字母、数字、空格和其他字符的个数
- java小练习:输入一个字符,判断该字符是数字?英文字母?还是其他字符
- oj第九周练习 统计出其中英文字母、数字、空格和其他字符的个数
- Java统计输入字符的英文字母、空格、数字和其它
- StChar.java 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- 用Java统计字符串中的字母、数字、空格和其他字符
- go语言之map练习之(一):统计字母、数字等Unicode中不同的字符类别出现的次数
- 题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。(java)
- java小算法—输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- java实现输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- java实现输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- C++练习之 统计英文字母,空格,数字和其他字符的个数