请编写程序,统计键盘录入的字符串中包含大写字母、小写字母、数字的个数,并测试

请编写程序,统计键盘录入的字符串中包含大写字母、小写字母、数字的个数,并测试

代码演示

****public class** MyTest2 **{**    **public static void** main**(**String**[]** args**) {**        /*
        统计键盘录入的字符串中包含大写字母、小写字母、数字的个数,并测试。
         */
        String str=**"S1f22d5b2S5F55h55C5h5h5455t1S5b5V8g985d5rC5dV"**;
        **int** num=0;
        **int** da=0;
        **int** xiao=0;
        **for** **(****int** i = 0; i < str.length**()**; i++**) {**            **char** ch=str.charAt**(**i**)**;
            **if** **(**ch>=**'a'**&&ch<=**'z'****){**                xiao++;
            **}****else if** **(**ch>=**'A'**&&ch<=**'Z'****){**                da++;
            **}****else** **{**                num++;
            **}**        **}**        System.**out**.println**(****"****大写字母有****"**+da+**"****个****"****)**;
        System.**out**.println**(****"****小写字母有****"** + xiao + **"****个****"****)**;
        System.**out**.println**(****"****数字字符有****"** + num+ **"****个****"****)**;
    **}****}**
发布了25 篇原创文章 · 获赞 3 · 访问量 324

猜你喜欢

转载自blog.csdn.net/weixin_45686974/article/details/102838901