CharacterDemo2
package cn.it;
import java.util.Scanner;
/*
*统计一个字符串中大写,小写,数字出现的次数
*/
public class CharacterDemo2 {
public static void main(String[] args) {
// 定义三个变量
int BigCount = 0;
int SmallCount = 0;
int NumberCount = 0;
// 键盘输入一个字符串
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String line = sc.nextLine();
// 把字符串转换为字符数组
char[] ch = line.toCharArray();
*统计一个字符串中大写,小写,数字出现的次数
*/
public class CharacterDemo2 {
public static void main(String[] args) {
// 定义三个变量
int BigCount = 0;
int SmallCount = 0;
int NumberCount = 0;
// 键盘输入一个字符串
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String line = sc.nextLine();
// 把字符串转换为字符数组
char[] ch = line.toCharArray();
// 遍历字符数组获取每一个字符
for (int x = 0; x < ch.length; x++) {
char ch1 = ch[x];
for (int x = 0; x < ch.length; x++) {
char ch1 = ch[x];
if (Character.isUpperCase(ch1)) {
BigCount++;
BigCount++;
} else if (Character.isLowerCase(ch1)) {
SmallCount++;
} else if (Character.isDigit(ch1)) {
NumberCount++;
}
}
//输出结果
System.out.println("大写:"+BigCount);
System.out.println("小写:"+SmallCount);
System.out.println("数字:"+NumberCount);
SmallCount++;
} else if (Character.isDigit(ch1)) {
NumberCount++;
}
}
//输出结果
System.out.println("大写:"+BigCount);
System.out.println("小写:"+SmallCount);
System.out.println("数字:"+NumberCount);
}
}
}