0

I have searched and I cant understand my error.

I have the following

while(logincount < 3){
if (tempuser.equals(actualuser) & (temppass.equals(actualpass))
  {
  System.out.println("Success");
  }
else  {
  System.out.println("FAIL");
    logincount=logincount+1;
  }
}

And because I cant copy from CMD; http://puu.sh/2svAo the error tells me its expecting a '>'

So I have tried &,&&, and the 2 I cant find the keys for right now.

Thanks, again sorry if this is stupid, I was downvoted to hell in my last question, so I hope this is 'better' ! :-)

Kieronboz
  • 85
  • 3
  • 14

4 Answers4

1

The line

if (tempuser.equals(actualuser) & (temppass.equals(actualpass))

Has an extra opening bracket, either

if (tempuser.equals(actualuser) & temppass.equals(actualpass))

or

if ((tempuser.equals(actualuser)) & (temppass.equals(actualpass)))

should work fine.

Edit: whoops, thanks to dukeling for noticing the typo I made on the last line. (fixed now)

Jordan Robinson
  • 855
  • 11
  • 25
  • 2
    You're missing 2 closing brackets on the last one, it should be `if ((tempuser.equals(actualuser)) & (temppass.equals(actualpass)))`. – Bernhard Barker Apr 02 '13 at 14:11
  • Thanks working fine now with a combo of your answer and comments above, though cant figure out why my loop wont exit now, haha. – Kieronboz Apr 02 '13 at 14:13
  • @T.Des I agree, `&` should almost always be `&&` since `&` won't short circuit, unless that is what he wants. – jn1kk Apr 02 '13 at 14:15
  • 1
    http://stackoverflow.com/questions/4014535/differences-in-boolean-operators-vs-and-vs for any confusion out there. – aglassman Apr 02 '13 at 14:19
0

Two errors there: 1. "(temppass" does need the preceeding "(" 2. "&" is a bitwise OR, you need a logical OR here: "&&"

So "if (tempuser.equals(actualuser) & (temppass.equals(actualpass))" becomes "if (tempuser.equals(actualuser) && temppass.equals(actualpass))"

Vitaly
  • 2,760
  • 2
  • 19
  • 26
0

Missing a ")" in the if statement, here is the correction

    while(logincount < 3){
        if (tempuser.equals(actualuser) & (temppass.equals(actualpass)))
          {
          System.out.println("Success");
          }
        else  {
          System.out.println("FAIL");
            logincount=logincount+1;
          }
        }
NullPointerException
  • 3,732
  • 5
  • 28
  • 62
0

You can improve your code a bit.

for (int i = 0; i < 3; i++) {
    if (tempuser.equals(actualuser) && temppass.equals(acutalpass)) {
        System.out.println("Success");
        break;
    } else {
        System.out.println("FAIL");
    }
}
  1. Use for loop instead of while loop so that initialization and increment of loop variable is done in one place.
  2. Use && instead of & for logical AND.
  3. Add a break statement if your password check succeeds.
maba
  • 47,113
  • 10
  • 108
  • 118