java第十次作业

1.输入6位密码,再次输入密码,如果不够6位,提示,位数不对,如果两次不一致,提示两次密码不一致。
 Scanner input = new Scanner(System.in);
        String pass;
        String repass;
        System.out.println("请输入6位密码");
        pass = input.next();
        testfun_1(pass);
        System.out.println("请重新输入密码");
        repass = input.next();
        testfun_1(repass);
        testfun_2(pass, repass);
    }

    public static void testfun_2(String test, String retest) {
        if (!test.equals(retest)) {
            System.out.println("密码不一致");
            System.exit(0);
        }
    }

    public static void testfun_1(String test) {
        if (test.length() != 6) {
            System.out.println("位数不对");
            System.exit(0);
        }
    }

    public static void main(String[] args) {
        pw();
    }

 2.输入一个字符串,判断里面数字、大写字母、小写字母,其他字符的个数

 Scanner input = new Scanner(System.in);
        int math = 0;
        int wordup = 0;
        int worddo = 0;
        int other = 0;
        System.out.println("请输入字符串");
        String test = input.next();

        for (char i : test.toCharArray()) {
            if (i <= 57 && i >= 48) {
                math++;
            } else if (i <= 90 && i >= 65) {
                wordup++;
            } else if (i <= 122 & i >= 97) {
                worddo++;
            } else {
                other++;
            }
        }
        System.out.println("数字有:" + math + "个");
        System.out.println("大写字母有:" + wordup + "个");
        System.out.println("小写字母有:" + worddo + "个");
        System.out.println("其他字符有:" + other + "个");
    }

 

 3.输入一个字符串,如果开头是ok并且包含no,那么输入错误。

 Scanner input = new Scanner(System.in);
        System.out.println("请输入字符串");
        String test = input.next();
        if (test.startsWith("ok") || test.contains("no")) {
            System.out.println("输入错误");
        }
    }

  4.输入三个单词,组合成pascal命名法的字符串。(选做)

String s_1 = "STU";
        String string_1 = s_1.substring(0, 1);
        String string_2 = s_1.substring(1, 3).toLowerCase();
        String s_2 = "manage";
        String string_3 = s_2.substring(0, 1).toUpperCase();
        String string_4 = s_2.substring(1, 6);
        String s_3 = "system";
        String string_5 = s_3.substring(0, 1).toUpperCase();
        String string_6 = s_3.substring(1, 6);
        System.out.println(string_1 + string_2 + string_3 + string_4 + string_5 + string_6);

    }

 

 

posted @ 2023-06-22 18:47  张云月  阅读(15)  评论(0)    收藏  举报