F 分类计数
时间限制: 1.0s 内存限制: 512.0MB 本题总分:15 分
问题描述
输入一个字符串,请输出这个字符串包含多少个大写字母,多少个小写字
母,多少个数字。
输入格式
输入一行包含一个字符串。
输出格式
输出三行,每行一个整数,分别表示大写字母、小写字母和数字的个数。
样例
Input:
1+a=Aab
Output:
1
3
1
import java.util.Scanner;
public class 试题F分类计数 {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
String s=sc.nextLine();
char[] a=s.toCharArray(); //字符串转字符
int xiaoxie=0,daxie=0,number=0;
for( int i=0;i<a.length;i++) {
if( (byte)a[i]>='a'&&(byte)a[i]<='z') { //字符转数值,然后对比
xiaoxie++;
}
if( (byte)a[i]>='A'&&(byte)a[i]<='Z') {
daxie++;
}
if( (byte)a[i]>='0'&&(byte)a[i]<='9') {
number++;
}
}
System.out.print(daxie+ "\n" +xiaoxie+ "\n" + number);
}
}