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
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.