-1
public class ControlFlow {

 public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    System.out.println("Are you hungry?\n");
    String answer = input.nextLine();
    input.close();
    if(answer == "yes") {
        System.out.println("Food is on the table!");
    }else {
        System.out.println("Not hungry!\n");
     }

  }

}

I tried with boolean variable too. It did not help

Deadpool
  • 33,221
  • 11
  • 51
  • 91
Md Nuhel
  • 55
  • 1
  • 6

1 Answers1

0

Just compare the content of the strings with:

"yes".equals(answer)
AndiCover
  • 1,663
  • 3
  • 16
  • 33