蓝桥杯2020年真题:分类计数

题目

时间限制: 1.0s 内存限制: 512.0MB 本题总分:15 分

【问题描述】
输入一个字符串,请输出这个字符串包含多少个大写字母,多少个小写字母,多少个数字。

【输入格式】
输入一行包含一个字符串。

【输出格式】
输出三行,每行一个整数,分别表示大写字母、小写字母和数字的个数。

【样例输入】 
1+a=Aab

【样例输出】 
1 
3 
1
【评测用例规模与约定】 
对于所有评测用例,字符串由可见字符组成,长度不超过 100

答案

package competition4;

import java.util.Scanner;

public class CountAllKind
{
    
    
	public static void main(String[] args)
	{
    
    
		Scanner in = new Scanner(System.in);
		String str=in.nextLine();
		in.close();
		int Big=0;
		int small=0;
		int digtal=0;
		
		for(int x=0;x<str.length();x++)
		{
    
    
			if(str.charAt(x)>='a' && str.charAt(x)<='z')
			{
    
    
				small++;
			}
			if(str.charAt(x)>='A' && str.charAt(x)<='Z')
			{
    
    
				Big++;
			}
			if(str.charAt(x)>='0' && str.charAt(x)<='9')
			{
    
    
				digtal++;
			}
		}
		System.out.println(Big);
		System.out.println(small);
		System.out.println(digtal);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_43416157/article/details/109006174