SwagiWagi SwagiWagi - 5 months ago 10
Java Question

Issue when comparing strings

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 your UserName: ");
vname = next.next();
System.out.println("Please enter your Password: ");
vpass = next.next();
} while ((name && pass).equals(vname && vpass));


How could 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();