- //统计一个字符串中大写字母字符,小写字母字符,数字字符出现的次数,其他字符出现的次数。
- //ABCDEabcd123456!@#$%^
- public class Test2_3 {
- public static void main(String[] args) {
- String str = "ABCDEabcd123456!@#$%^";
- int big=0,small=0,num=0,other=0;
- char[] ch = str.toCharArray();
- for (int i = 0; i < ch.length; i++) {
- if (ch[i]>='A'&&ch[i]<='Z') {
- big++;
- }else if (ch[i]>='a'&&ch[i]<='z'){
- small++;
- }else if (ch[i]>='0'&&ch[i]<='9'){
- num++;
- }else{
- other++;
- }
- }
- System.out.println("小写" + small + "个,大写" + big + ",数字" + num + "个,其他" + other + "个");
- }
- }
复制代码 |
|