重置布尔值?

用户名

我正在尝试让我的密码验证程序循环播放,直到给出正确的响应为止。它现在正在循环,但在第一次迭代后没有重置布尔值,因此无论使用哪个密码,第二次都将得到有效的响应。如何对每个值进行循环检查,或者每次都重置表?

            boolean atLeast8 = false;                   
        boolean oneLower = false;                   
        boolean oneUpper = false;                   
        boolean oneNumber = false;                  
        boolean oneSpecial = false;                 
        boolean noAnd = false;                      
        boolean noEnd = false;  


            do
        {
            System.out.println("Enter your password. " + '\n');
            password = input.nextLine();
            System.out.println();




            for(int i=0; i<password.length(); i++)      //Checks for values througout the length of the string

            {
                char c = password.charAt(i);
                if(password.length() >= 8)
                atLeast8 = true;

                if(Character.isLowerCase(c))
                oneLower = true;

                if(Character.isUpperCase(c))
                oneUpper = true;

                if(Character.isDigit(c))
                oneNumber = true;

                if(c=='!' || c=='@' || c=='#' || c=='$' || c=='%' || c=='^' || c=='&' || c=='&' || c=='*')
                oneSpecial = true;

                if (password.indexOf("and") < 0)
                noAnd = true;

                if (password.indexOf("end") < 0)
                noEnd = true;

            }
            if(atLeast8 && oneLower && oneUpper && oneNumber && oneSpecial && noAnd && noEnd)   //Does the string contain any true values?
                {
                    System.out.println("Valid.");
                }
            else
                {
                    System.out.println("Invalid!");                                                 //Does the string contain any false values?
                }

                if(!atLeast8)
                {
                    System.out.println("Must be at least 8 characters long.");


                }
                if(!oneLower)
                {
                    System.out.println("Must contain one lower case letter.");

                }
                if(!oneUpper)
                {
                    System.out.println("Must contain one upper case letter.");

                }
                if(!oneNumber)
                {
                    System.out.println("Must contain one numeric digit.");

                }
                if(!oneSpecial)
                {
                    System.out.println("Must contain one special character.");

                }
                if(!noAnd)
                {
                    System.out.println("Must not contain the word 'and'.");

                }
                if(!noEnd)
                {
                    System.out.println("Must not contain the word 'end'.");

                }
        }while (atLeast8 == false || oneLower == false || oneUpper == false || oneNumber == false || oneSpecial == false || noAnd == false || noEnd == false);
    }

}
脚本

你不能放

    atLeast8 = false;                   
    oneLower = false;                   
    oneUpper = false;                   
    oneNumber = false;                  
    oneSpecial = false;                 
    noAnd = false;                      
    noEnd = false;  

在循环开始时(在“ do {”和“ for”之间的某个位置)

还是太简单了?

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章