遍历字符串之后,在判断字符串中的大小写的时候为什么要bigcount++,smallcount++.
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一行字符串...");
String str = scanner.nextLine();
int big = 0; // 定义一个变量来存取大写字母的数量
int small = 0; // 定义一个变量来存取小写字母的数量
int number = 0; // 定义一个变量来存取数字的数量
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
// 判断如果是大写字母
if(c <= 'Z' && c >= 'A'){
// 存取大写字母数量的变量值加1
big++;
}
if(c <= 'z' && c >= 'a'){
small++;
}
if(c >= '0' && c <= '9'){
number++;
}
}
System.out.println("大写" + big);
System.out.println("小写" + small);
System.out.println("数字" + number);
希望能帮到你奥~
这是在计算大小写字母的个数吧
朋友你把代码贴上来把,你这提问太唐突了。另外你可能还没有学到 变量的 自增 和 自减。