Java:输入文本统计其中数字,大小写字母、空格和其他字符的个数

class Stat_char{
int number = 0,capital_letter = 0, lowercase = 0 ,blank = 0, rests_char = 0;
Scanner in = new Scanner(System.in);
public void show()
{
System.out.print(“请输入一串字符串统计其中字符的个数:”);
String c1 = in.nextLine();
char []a = c1.toCharArray();
for(int i = 0 ; i<a.length ; i++)
{
if(a[i]>=‘0’&&a[i]<=‘9’)
{
number++;
}else if(a[i]>=‘A’&&a[i]<=‘Z’)
{
capital_letter++;
}else if(a[i]>=‘a’&&a[i]<=‘z’)
{
lowercase++;
}else if(a[i]==’ ')
{
blank++;
}else
{
rests_char++;
}
}
}
public void print()
{
System.out.println(“数字有:”+number+“个”);
System.out.println(“大写字母有:”+capital_letter+“个”);
System.out.println(“小写字母有:”+lowercase+“个”);
System.out.println(“空格有:”+blank+“个”);
System.out.println(“其他字符有:”+rests_char+“个”);
}
}
public class Sample_2_22 {

public static void main(String[] args) {
	Stat_char ch = new Stat_char();
	ch.show();
	ch.print();
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值