string - Java Help (possibly a glitch in eclipse) -
this question has answer here:
- how compare strings in java? 23 answers
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
Post a Comment