输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。


输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。

输入

一行字符

输出

统计值

样例输入
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
样例输出
23 16 2 4


import java.util.Scanner;
public class Main {
public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  String n = in.nextLine();
  int count1=0;
  int count2=0;
  int count3=0;
  int count4=0;
  char a[] = n.toCharArray();
  for(int i=0;i<a.length;i++){
  if(a[i]>='a'&&a[i]<='z'||a[i]>='A'&&a[i]<='Z'){
    count1++;
  }
  else if(a[i]==' '){
    count2++;
  }
  else if(a[i]>='0'&&a[i]<='9'){
    count3++;
  }
  else
    count4++;
  }
  System.out.print(count1+" "+ count3 + " "+count2+" "+count4);

}

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM