If, String, and Scanner
Why after entering "YES" into the console the condition from the first "IF" is not displayed It is always returned "ELSE": Scanner scan = new Scanner(System.in); String odp = scan.next(); if (odp == "YES"){ System.out.println("Print 1"); } else if (odp == "NO"){ System.out.println("Print 2"); } else{ System.out.println("Anything else"); } In the case of "int" everything works as it should. For example: Scanner scan = new Scanner(System.in); int odp = scan.nextInt(); if (odp == 1){ System.out.println("Print 1"); } else if (odp == 2){ System.out.println("Print 2"); } else{ System.out.println("Anything else"); }