在线提示 Java : 外部错误还是我自己的错误?

Online prompt Java : external error or my own error?

现在让我们的代码开个玩笑。阅读下面的代码和评论。

我们想将该提示代码移动到 do while 循环中。将代码包装成一个 do while 代码块并检查 while 条件以查看谁是 "banana" 以便循环继续。

提示:请记住将您的 who 声明移到 do 块之外,以便可以访问它。 需要遵循的算法:

/*  So the age old knock knock joke goes like this:

    Person A:  Knock Knock.
    Person B:  Who's there?
    Person A:  Banana
    Person B:  Banana who?
    ...as long as Person A has answered Banana the above repeats endlessly
    ...assuming the person answers Orange we'd see
    Person B:  Orange who?
    ...and then the punchline.
    Person A:  Orange you glad I didn't say Banana again?
    (It's a really bad joke that makes it sound like "Aren't you glad I didn't say Banana again?")

    Let's just assume the only two words passed in from the console from Person B are either banana or orange.
*/

MY ATTEMPT:
// Person B asks and Person A's response is stored in the String who:
String who;
boolean response;
boolean orangse;
do{
  who = console.readLine("Who's there?  ");
  response = who.equalsIgnoreCase("banana");
  orangse = who.equalsIgnoreCase("orange");
  console.printf(who);
  while (response){
    console.printf("%s who?\n", response);
  }
  if (orangse) {
    console.print("Orange you glad I didn't say Banana again?");
  }
}

// ==== 结束提示代码 ====

您在 do 块之后缺少 while他们一起去.

Java 中 do ... while 的语法是:

do {
    // some statements
} while (/*condition*/);

More info