键盘录入一个字符串,统计该字符串中大写字母字符,小写字母字符,数字字符出现的次数(不考虑其它字符)
运用ASCII码
- a-z 97-122
- A-Z 65-90
- 0-9 48-57
考虑知识点:
1、计数统计
2、字符串遍历
3、字符串在编码集中区间的区域,判定它是什么类型的字符
4、char数据类型在参与运算时,会无条件提升为int再计算
示例代码:
public class HomeworkTest01 {
public static void main(String[] args) {
String s = "ABCDefgsji1234hjizsdlhniknHGD4789VVHBUmcihsnjv";
int upper = 0;
int lower = 0;
int num = 0;
for(int i = 0;i<s.length();i++){
char c = s.charAt(i);
if(c>='A' && c<='Z'){
upper++;
}
if(c>='a' && c<='z'){
lower++;
}
if(c>='0' && c<='9'){
num++;
}
}
System.out.println("大写字符出现的次数为"+upper+"次,小写字符出现的次数为"+lower+"次,数字出现的的次数为"+num+"次");
}
}