我是一個初學者與Java和我下面的Thenewboston在YouTube上的教程。我想要更高級一點(在我看來......但不是真的)。所以繼承了代碼。我想讓它重複到開頭,這樣我就可以輸入另一個數字而無需重新啓動程序。我相信我必須使用返回命令,但我不確定在哪裏以及如何。謝謝!如何重複/循環/返回到一個類
import java.util.Scanner;
class apples {
public static void main(String args[]) {
Scanner alex = new Scanner(System.in);
Double test;
test = alex.nextDouble();
if (test == 9) {
System.out.println("eat");
} else {
System.out.println("do not eat");
}
}
}
謝謝。 while(true)語句的含義是什麼? – user1174394 2012-01-27 21:27:29
這意味着「永遠重複」; while(條件){語句}將執行「語句」,直到「條件」變爲假 – 2012-01-27 21:47:17
true始終爲真,所以你的程序將繼續輸入,直到你殺了它:) – 2012-01-27 21:53:49