dimanche 24 janvier 2016

Nested if returning unreachable code

I'm doing a (pseudo) AI interface of questions and answers, my 'answer' class is a bunch of if's statements: if "a" in message then return this "b".

I want to be able to give it more depth, by inserting nested if's, but that second if is giving "Unreachable code". What can I do to solve it? Is there a better way to do what i'm trying?

Main class:

System.out.println("Type your message:");
String message = talkback.beginAnswers(in.nextLine());

...

beginAnswers class:

public String beginAnswers (String message) {

if("nothing".equalsIgnoreCase(message)) {
 return "Are you sure?";

     if("yes".equalsIgnoreCase(message)) {
       return "ok";
        }
   }

  ....

}

Aucun commentaire:

Enregistrer un commentaire