mercredi 16 novembre 2016

How to make java only print one message with if statements

So im trying to make a program that asks two questions for school. The problem im having is java keeps printing more than one message when I only want one. Is anyone able to tell me how to do it right? Here is the code:

  if (answer1.equals("inside") ||
     answer1.equals("outside") ||
     answer1.equals("both") ) 
     System.out.println("Question 2) Is it a living thing?(yes/no)");
     answer2 = keyboard.next();

  if (answer2.equals("yes") ) 
     System.out.println("Then what else could you be thinking of besides a houseplant?!");

  if (answer2.equals("no") ) 
     System.out.println("Then what else could you be thinking of besides a shower curtain?!");

  if (answer2.equals("yes") ) 
     System.out.println("Then what else could you be thinking of besides a bison?!");

  if (answer2.equals("no") ) 
     System.out.println("Then what else could you be thinking of besides a billboard?!");

  if (answer2.equals("yes") ) 
     System.out.println("Then what else could you be thinking of besides a dog?!");

  if (answer2.equals("no") ) 
     System.out.println("Then what else could you be thinking of besides a cell phone?!");
  }

}

Aucun commentaire:

Enregistrer un commentaire