分析以下需求,并用代码实现: 
        (1)从键盘录入一个字符串 
        (2)统计该串中有大写字母、小写字母、数字各有多少个。 
                举例: 
                        Hello12345World 
                        大写 : 2个 
                        小写 : 8个 
                        数字 : 5个 
答: 
        package apiTest; 
 
import java.util.Scanner; 
 
public class Test5 { 
        public static void main(String[] args) { 
                Scanner sc = new Scanner(System.in); 
                System.out.println("请输入一个字符串"); 
                String s = sc.nextLine(); 
                int big = 0; 
                int small = 0; 
                int num = 0; 
                int other = 0; 
                for (int x = 0; x < s.length(); x++) { 
                        char c = s.charAt(x); 
                        if (c >= 'A' && c < 'Z') { 
                                big++; 
                        } else if (c >= 'a' && c <= 'z') { 
                                small++; 
                        } else if (c >= '0' && c <= '9') { 
                                num++; 
                        } else { 
                                other++; 
                        } 
                } 
                System.out.println("输入的字符串中大写字母:" + big + "个,小写字母:" + small + "个,数字:" + num + "个,其他字符:" + other + "个"); 
        } 
} 
 
 
 |   
        
 
    
    
    
     
 
 |