SwagiWagi SwagiWagi - 5 months ago 7
Java Question

Can't understand what is wrong

I'm trying to check if two strings are equals to each other (If

name
and
pass
are equals to
vname
and
vpass
).

do {
System.out.println("=-=-=-=-=-=-Login-=-=--=-=-=");
System.out.println("Please enter you UserName: ");
vname = next.next();
System.out.println("Please enter your Password: ");
vpass = next.next();
} while ((name && pass).equals(vname && vpass));


How do I make it so it will work?

Answer

This here is not correct:

while((name && pass).equals(vname && vpass));

do instead something more coherent like:

while(!(name.equals(vname)) || !(pass.equals(vpass))  );

and for preventing wrongly read inputs replace this:

vname = next.next();

for this:

 vname = next.nextLine();
Comments