It's a part to for which am entering the date 27 june ( to have the logic correct) , but still it prints the date is not correct(logic fails).
I don't understand why is it 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 the correct date");
}
else {
System.out.println("no thats not the correct date");
}
You need to compare objects (including strings) using
equals()
instead of==
: