java - The logic is always failing -
it's part entering date 27 june ( have logic correct) , still prints date not correct(logic fails).
i don't understand why still failing.
**code:** scanner date = new scanner(system.in); scanner month = new scanner(system.in); system.out.println("enter date"); int dat = date.nextint(); string mon= "june"; //string month="feb"; system.out.println("now enter month"); string mont= month.nextline(); if (dat== 27 && mont==mon) { system.out.println("yes thats correct date"); } else { system.out.println("no thats not correct date"); }
you need compare objects (including strings) using equals()
instead of ==
:
if (dat== 27 && mont.equals(mon)){ // ... }
Comments
Post a Comment