String issue - Java -



String issue - Java -

i writing programme class in analyze different product codes entered. pretty simple having problem. trying end loop if user enters "e" or "e". however, not end loop @ all. @ end of while statement setting loop false should end , doesn't output totals either have messed up. code string type.

// prompt user company code or exit system.out.print("enter company code or type 'e' exit: "); // input user's company code code = scan.nextline(); // check see if user wants exit if (code == "e" || code == "e") { // output final statistics system.out.print("total valid codes: " + valid + "/n"); system.out.print("total banned codes: " + banned); // end loop loop = false; }

any ideas? thanks!

you need utilize code.equals("e") || code.equals("e") (or code.equalsignorecase("e")). because == identity comparing ("are x , y same object?"), whereas equals value comparing ("do x , y have same value?").

java string compare equals equality

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -