public class Tes07 {
public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("输入一串字符:"); Scanner input=new Scanner(System.in); String str=input.nextLine(); int index = 0; char c; int count1=0; int count2=0; int count3=0; int count4=0; for(int i=0;i<str.length();i++) { c=str.charAt(index++); if(c>=65&&c<=90||c>=97&&c<=122){ count1++; }else if(c==32){ count2++; }else if(c>=48&&c<=57){ count3++; }else { count4++; } } System.out.println( "字母数:"+count1 +"空格数:"+count2 +"数字数:"+count3 + "其他字符:"+count4); }
}
文章来源: https://blog.csdn.net/weixin_44944367/article/details/90241495