-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

Ryuzaki L
  • 37,302
  • 12
  • 68
  • 98
Md Nuhel
  • 75
  • 1
  • 6

1 Answers1

0

Just compare the content of the strings with:

"yes".equals(answer)
AndiCover
  • 1,724
  • 3
  • 17
  • 38