0

String username;

String password;

if (username!="admin" && password!="software")

        System.out.print("success");

else if (username!="admin" && password=="software")

        System.out.print("failure");

guyz could you plzz explain when admin and password are both equal to their respective values i.e. admin and software than it prints success but if i say username is equal to admin and password is not equal to software it also prints success again

Moreover, i took input in username and password like this

password = Pass_input.getText();

username = Username_input.getText();

while Username_input and Pass_input are the JtextFields in java

Cœur
  • 37,241
  • 25
  • 195
  • 267
Abdul Wahab
  • 99
  • 1
  • 2
  • 11
  • 1
    Use .equals method to compare the strings, Your need is to compare string values whereas you are comparing objects in you scenario. – Rishal Aug 07 '16 at 18:19
  • if (username.equals(user)) { if (password.equals(pass)) { System.out.print("success"); } else { System.out.print("failure wrong password"); } } – Abdul Wahab Aug 08 '16 at 01:42
  • portion of code above is working absolutely fine but bro equal here commpare values what if i want to say that if username is not equal to admin and password is also not equal to software print failure wrong username and password what to do for that – Abdul Wahab Aug 08 '16 at 01:42
  • else if (username=="admin" && password=="software") //i am facing problem here it is printing nothing on the screen { System.out.print("failure wrong username and password"); } – Abdul Wahab Aug 08 '16 at 01:43
  • else if (username.equals(user)== false && password.equals(pass)==false) { System.out.print("failure wrong username and password"); } – Abdul Wahab Aug 08 '16 at 01:54
  • it worked like this if it is correct or not ? what is your opinion @Rishaldevsingh – Abdul Wahab Aug 08 '16 at 01:54
  • then use something like (!username.equals(user)), here "!" will give you the opposite of equals. – Rishal Aug 08 '16 at 05:15

0 Answers0