Simple login with Java code - using conditional assignment -


this question has answer here:

i'm still newbie java programming. , can tell me what's wrong source code? when run code, conditional assignment outputs "login failed".

import java.util.scanner; public class programbiodatamahasiswa {     public static void main(string[] args) {         scanner input = new scanner(system.in);         string username, password, output;         system.out.print("enter username     : ");         username = input.nextline();         system.out.print("enter password     : ");         password = input.nextline();         output = (username=="kesit" && password=="ps123") ? "login successfully" : "login failed" ;         system.out.println(output);     } } 

with strings ("quest" , "ps123") shouldn't using == check if equal. compare pointer , due fact string in java immutable, pointers different. therefore use

username.equals("kesit") && password.equals("ps123"). 

that should work!


Comments

Popular posts from this blog

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -