使While语句为真(从另一个类调用方法) [英] Make While Statement True (Calling Method from Another Class)

查看:75
本文介绍了使While语句为真(从另一个类调用方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class Driver {
    public static void main(String args[]) {

        Encryption pass = new Encryption();

        while(CODE){
            System.out.println("Please enter a password");
            String name = KeyboardReader.readLine();

            System.out.println("Encrypted Password:  " + pass.encrypt(name));
            System.out.println("Decrypted Password:  " + pass.decrypt(name));
        }
    }

    boolean isValidLength (String password) {
        if (password.length() < minLength) {
            return true;
        } else {
            return false;
        }
    }
}

如何使上面的说法正确?我需要这样做,以便如果用户输入的密码时间不够长或不是有效的密码,他们可以一遍又一遍地重新输入.不知道我的while循环是否正确,但是我必须从isValidLength方法中调用以使其正确.发现任何错误也将有所帮助.

How would I go by making the statement true above? I need to make it so that if the user enters a password not long enough or not a valid password they can re enter it over and over again. Not sure if my while loop is correct, but I have to call from my isValidLength method to make it true. Any mistakes found would be helpful too.

推荐答案

类似于以下内容:

while(true){
    //read the password
    ...
    if (isValidLength(password)){
        break;
    }
}
//proceed with encryption
...

这篇关于使While语句为真(从另一个类调用方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆