输入一个字符串,对里面的字符类型进行统计
package chapter13.Test;
/**
* @Author Java顶针
* @Version 1.0
*/
public class Test04 {//判断字符串里包含多少个大、小写字母、数字
public static void main(String[] args) {
String name = "ASefsfjklAAEf56Effd55";
CountStr(name);
}
public static void CountStr(String str){
if (str == null) {
System.out.println("输入不能为空");
return;
}
int numCount = 0;
int lowerCount = 0;
int upperCount = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) >= '0' &&str.charAt(i) <= '9') {
numCount++;
}else if (str.charAt(i) <= 'z' && str.charAt(i) >= 'a'){
lowerCount++;
}else if (str.charAt(i) <= 'Z' && str.charAt(i) >= 'A'){
upperCount++;
}else {
System.out.println("其他数字不统计");
}
}
System.out.println("小写字母有"+lowerCount+"\t大写字母有"+upperCount+"\t数字有"+numCount);
}
}
标签:练习题,常用,java,String,int,lowerCount,System,str,upperCount
From: https://blog.csdn.net/m0_66130067/article/details/143808534