统计--键盘输入的字符串中各种字符的个数

博客聚焦于统计从键盘输入的字符串中各种字符的个数,属于信息技术中数据处理相关内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

统计–键盘输入的字符串中各种字符的个数

package ShangXueTang;
//自动导包:sc+alt+/
import java.util.Scanner;

/*题目:统计--键盘输入的字符串中各种字符的个数
 */

public class Test_02 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请键盘输入字符串:");
		String input = sc.next();

		int countdaxie = 0; // 累加 大写字母的
		int countxiaoxie = 0; // 小写字母
		int countshuzi = 0; // 数字
		int countother = 0; // 其它

		// 将键盘输入的字符串 转换成 字符数组
		char[] charArray = input.toCharArray();
		// 遍历数组 获取 每个字符
		for (int i = 0; i < charArray.length; i++) {
			//获取到每一个字符
			char dange = charArray[i];
			//判断
			if ('A' <= dange && dange <= 'Z') {
				countdaxie++;
			} else if ('a' <= dange && dange <= 'z') {
				countxiaoxie++;
			} else if ('0' <= dange && dange <= '9') {
				countshuzi++;
			} else {
				countother++;
			}
      
		}
    
	System.out.println("大写字母总个数:"+countdaxie);
	System.out.println("小写字母总个数:"+countxiaoxie);
	System.out.println("数字总个数:        "+countshuzi);
	System.out.println("其它字符总个数:"+countother);
	}

}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值