خرید بک لینک

Vote count: 0

The askYesNoQuestion(str) should print out the string str as a question for the user. If the user enters string "yes", the askYesNoQuestion(str) method should retu true; if the user enters "no" the method should retu false.

Why does this method retu true as an answer when user enters "no" ?

import acm.program.*;

public class YesNoQuestion extends ConsoleProgram{
    public void run(){
        println("This program asks user for instructions");

        println(askYesNoQuestion("Would you like instructions ?"));
    }

    private boolean askYesNoQuestion(String str){

        String ans = readLine(str);

        if (ans.equals("yes") || ans.equals("no")){
            retu true;
        } else if (ans.equals("no") || ans.equals("No")){
            retu false;
        } else {
            println("Please answer with yes or no.");
            retu askYesNoQuestion(str);
        }
    }

}

asked 45 secs ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: جمعه 25 تير 1395 ساعت: 22:17

صفحه بندی