Can someone explain why the below JAVA multi condition code don't provide the correct Output.
Even if i provide a input Which satisfies the condition it still give a false result. for eg: Input : US 25 Output : Not sure ( It should perform the if condition which it is not doing. I want to know why its not working. for the same program if i use "equals" it is working. but not sure what is Wrong while using the == Operator. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String country = sc.nextLine(); int age = sc.nextInt(); if ((country=="US"||country=="GB")&&(age>=18 && age<=100)) { System.out.println("Country: "+ country ); System.out.println("Age :"+ age); }else{ System.out.println("Not sure!!"); } } } Working Code : import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String country = sc.nextLine(); int age = sc.nextInt(); if ((country.equals("US")||country.equals("GB"))&&(age>=18 && age<=100)) { System.out.println("Country: "+ country ); System.out.println("Age :"+ age); }else{ System.out.println("Not sure!!"); } } }