Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can i fix algorithms problem in login

i try to make login app in java for begginer level
i tried thease codes but it not works everything works true but if state did not work

this is my source code

public class Main {
    public static void main(String[] args) {
        String username = "admin";
        String password = "1234";

        String iuser;
        String ipass;

        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter Username");
        iuser = scanner.next();
        System.out.println("Enter Password");
        ipass = scanner.next();

        System.out.println(ipass);
        System.out.println(iuser);


       if(username == iuser ){
            System.out.println("Logged in");
            }
       else {

           System.out.println("not logged");

       }



    }
}

and this is the output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Enter Username
admin
Enter Password
1234
1234
admin
not logged


so how can i fix it

>Solution :

At username == iuser, it should be username.equals(iuser). See String.equals versus ==

Works for me after that.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading