package com.test;
public class Test3Search {
/*
* 统计字符串ABCDEabcdef123456*()^%%的大写字母,小写字母,数字,其他字符的个数
* 1.先获取每个字符
* 2.判断字符属于哪种
* 3.统计
*/
public static void main(String[] args) {
String s = "ABCDEabcdef123456*()^%%";
int big = 0;
int small = 0;
int num = 0;
int other = 0;
for(int i = 0; i<s.length(); i++) {
char ch = s.charAt(i); //通过索引获取每个字符
if(ch>='A' && ch<='Z') {
big++;
}else if(ch>='a' && ch<='z') {
small++;
}else if(ch>='1' && ch<='9') {
num++;
}else {
other++;
}
}
System.out.println("大写字母个数是:"+big+",小写字母个数是:"+small+",数字的个数是:"+num+",其他字符个数是:"+other);
}
}
统计字符串ABCDEabcdef123456*()^%%的大写字母,小写字母,数字,其他字符的个数
最新推荐文章于 2022-05-21 18:33:58 发布