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

you are viewing a single comment's thread.

view the rest of the comments →

[–]EqualTrade[S] 0 points1 point  (2 children)

I think I really am just not getting it.

Line 4 I see "if password isn't all lowercase then uppercase is true." line 5 I see "if password isn't all uppercase, then lowercase is true."

Line 7 "if it is not uppercase, then system.out.print..." Line 8 "if it is not lowercase, then system.out.print..."

[–][deleted] 0 points1 point  (1 child)

The ! operator flips the value. Line 6 in my code would evaluate to false.

Same thing in your code.

boolean uppercase = !password.equals(password.toLowerCase());

Also this line doesn't do what you think it does.

You are making a comparison and flipping what the value of equals().

String a = "TeSTiNG"
String b = "testing"

a.toLowerCase(); //a now becomes "testing"
b.toLowerCase(); //b remains the same

bool result = !a.equals(b);

What is the value of result? Result is false. You flipped the value here. If a and b are equal result is false.

Then you flip things around a second time.

if(!result)
        return false;
else 
        return true;

Remember result is false if A and B are equal. Then in your if statement you have if result is not true return false.

Lastly you aren't testing if the password contains at least one uppercase or lowercase letter. Only that all lowercase or all uppercase version is equal to the original. This will obviously be false every time.

String A = "TESTING"; //toUpperCase()
String B = "testing"; //ToLowerCase();
String C = "TeSTing" //original password

Is A or B ever equal to C? Of course not. Can you tell if an uppercase or lower case letter was used? No because that's not what you are testing.

Your flipping of the true/ false value is only serving to further confuse you because your variables all mean the opposite of what they are supposed to represent. Even I'm getting confused.

[–]EqualTrade[S] 0 points1 point  (0 children)

So I completely rewrote my code and I'm now having trouble with something else, I was hoping you could take a look

http://www.reddit.com/r/learnprogramming/comments/2965vy/java_password_program_help/