关于#java#的问题,如何解决?

键盘录入用户名和密码和已知的用户名和密码比较,模拟用户登录,给三次机会,如果信息一致,则提示“登录成功 否则,提示“您还剩x次机会”如果达到三次了。提示“您的账号被锁定 请联系管理员

这不是用if就可以解决了吗

 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String username = "admin";
        String password = "123456";
        int count = 3;
        while (count > 0) {
            System.out.println("请输入用户名:");
            String inputUsername = sc.nextLine();
            System.out.println("请输入密码:");
            String inputPassword = sc.nextLine();
            if (inputUsername.equals(username) && inputPassword.equals(password)) {
                System.out.println("登录成功!");
                break;
            } else {
                count--;
                if (count == 0) {
                    System.out.println("您的账号被锁定,请联系管理员!");
                } else {
                    System.out.println("您还剩" + count + "次机会!");
                }
            }
        }
    }