string - Java Help (possibly a glitch in eclipse) -


this question has answer here:

import java.util.scanner; import java.util.random;    public class cominback{     public static void main(string args[]){       scanner key = new scanner(system.in);       system.out.println(" please enter password:");       string x = key.nextline();       system.out.println("connfirm password:");       string y = key.nextline();       if ( x == null)           system.out.println("please restart program:");       if (x != y)           system.out.println("wrong password");       if (x == y )           system.out.println("you logged in");      } } 

it print out wrong password when input same passwords. how can fix problem? did wrong or eclipse glitching?

you should use equals method compare 2 string like:

if (x.equals(y))//password matches 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -