輸入一行字符,分別統計出其中英文字母、數字、空格和其他字符的個數。


輸入一行字符,分別統計出其中英文字母、數字、空格和其他字符的個數。

輸入

一行字符

輸出

統計值

樣例輸入
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