import java.util.Scanner;
public class StringDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入字符串:");
Scanner sc=new Scanner(System.in);//从控制台输入字符串
String str=sc.nextLine();
System.out.println(str);
char[] ch=str.toCharArray();//字符串转化成字符数组
int count1=0,count2=0,count3=0;
for (int i = 0; i < ch.length; i++) {
if(ch[i]>='0'&&ch[i]<='9')
count1++;
else
if(ch[i]>='A'&&ch[i]<='Z')
count2++;
else
if(ch[i]>='a'&&ch[i]<='z')
count3++;
}
System.out.println("数字个数为:"+count1);
System.out.println("大写字母个数为:"+count2);
System.out.println("小写字母个数为:"+count3);
System.out.println("其他字符个数为:"+(ch.length-count1-count2-count3));
}
}
|