题目-1002-字符串分类统计

 

 

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4 
 5     public static void main(String[] args) {
 6         Scanner in = new Scanner(System.in);
 7         
 8         while(in.hasNext()) {
 9             String s = in.nextLine();
10             item(s);
11         }
12         in.close();
13     
14     }
15     
16     
17     private static void item(String s) {
18         int alphanumeric = 0; // 字母
19         int number = 0;
20         int space  = 0;
21         int other = 0;
22         
23         for(int i = 0;i<s.length();i++) {
24             if(s.charAt(i)>='a'&&s.charAt(i)<='z'||s.charAt(i)>='A'&&s.charAt(i)<='Z') {
25                 alphanumeric++; 
26             }else if(s.charAt(i)>='0'&&s.charAt(i)<='9') {
27                 number++;
28             }else if(s.charAt(i)==' ') {
29                 space++;
30             }else {
31                 other++;
32             }
33         }
34         System.out.println(alphanumeric+" "+number+" "+space+" "+other);
35     }
36 }
37     

 

posted @ 2020-08-10 14:11  vkd  阅读(157)  评论(0)    收藏  举报