输入一个字符串,分别统计字符串中出现的大写字母、小写字母个数,以及出现的数字字符以及其他字符的个数。
输入格式:
输入一个字符串。
输出格式:
输出字符串中大写字母、小写字母个数,以及出现的数字字符以及其他字符的个数。
输入样例:
在这里给出一组输入。例如:
aBc3#d?>2D
输出样例:
在这里给出相应的输出。例如:
小写字母有: 3个
大写字母有: 2个
数字有: 2个
其他字符有: 3个
代码示例:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner put = new Scanner(System.in);
String str = put.next();
char[] array = str.toCharArray();
int a=0,b=0,c=0,d=0;
for(int i=0;i<array.length;i++) {
char ch = array[i];
if('A'<= ch&&ch <='Z') {
b++;
}else if('a'<= ch&&ch <='z') {
a++;
}else if('0'<= ch&&ch <='9') {
c++;
}else {
d++;
}
}
System.out.println("小写字母有: "+a+"个");
System.out.println("大写字母有: "+b+"个");
System.out.println("数字有: "+c+"个");
System.out.println("其他字符有: "+d+"个");
}
}