import java.util.Scanner;
public class Character2 {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("请输入一个字符串");
String line =sc.nextLine();
int uppercase=0;
int lowercase=0;
int digit=0;
char []arr =line.toCharArray();
for (char c : arr) {
if(Character.isUpperCase(c))
uppercase++;
else if(Character.isLowerCase(c))
lowercase++;
else if(Character.isDigit(c))
digit++;
}System.out.println("大写字母:"+uppercase+"个;小写字母:"+lowercase+"个;数字字母:"+digit+"个");
}
}
|
|