I wrote this simple code of logical operators but not getting desired output.
Output that I am getting : Enter age:package logical_operators; import java.util.Scanner; public class LogicalOperators { public static void main(String[] args) { try(Scanner opr = new Scanner(System.in)){ System.out.println("Enter age: "); int age = opr.nextInt(); opr.nextLine(); System.out.println("Do you have a ticket? "); String ticket = opr.nextLine(); if(age >= 18 && ticket == "yes") { System.out.println("You are eligible to take the flight."); } else if(age < 18 || !ticket.equals("yes")) { System.out.println("You are not eligible to take the flight."); } } } }
Input: 18
Do you have a ticket?
Input: yes
*****No output*****
Desired Output: You are eligible to take the flight.