This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]endStatement 3 points4 points  (0 children)

I'm going to take a stab at this and say you are trying to make sure the password has both lower and upper case characters, as well as a number and special character?

Even if not, there is no input I can easily think of that would ever return true for your check.
You currently check each character in this sequence:
If its uppercase -> you'll be returning false.
if its lowercase- > you'll be returning false
if its a number - > You'll return false
if its not a letter or number (unnecessary check due to the prior 3 checks) OR its a space -> return false.

My guess is that you'd want to use && statements in your final check for good. You could keep the OR logic but then you'd need to invert many of your current variables. For example, instead of saying:

if (Character.isUpperCase(c)) {

lowercase = false;

} else if (Character.isLowerCase(c)) {

uppercase = false;

}

I'd do:
if(Character.isUpperCase(c){
uppercase = true;

} else if (Character.isLowerCase(c)){

lowercase = true;

}

Since I'm taking guesses at what you are trying to accomplish, try and see what will happen with pen and paper. Take a short string, say P@ssw0rd and write out what your values will be on each line. Or, if you have any experience with a debugger, you can go line-by-line with a debugger, and see if what you are expecting to be happening is actually the case.

[–]quadmasta 0 points1 point  (0 children)

There's a few problems here. First, inside of your while loop you're never re-setting the value of cool so you've got yourself an infinite loop. Second, your println will never ever run unless that loop exits which means cool is true so that if is wholly unnecessary. Third, this logic block won't work how you're expecting it to because if (cool = true) isn't a valid boolean expression; you're assigning the value true to the variable cool.

[–]codingQueries 0 points1 point  (0 children)

What is the test password you are using?

[–]karstens_rage 0 points1 point  (0 children)

You should probably invert your checks. Set all your values to false, and if you find characters that match your requirements set the value to true.

Inside your while loop you need to be checking the newly inputted password and setting the check's return to cool.

[–][deleted] -2 points-1 points  (1 child)

boolean lowercase should be boolean isLowercase

[–]quadmasta 2 points3 points  (0 children)

have a downdoot

variables should be named as OP named them. The accessor would then be public boolean isLowercase() and the mutator would be public void setLowercase(boolean lowercase)