← 從零開始學 Java
第 16 課,共 88 課 · 10 XP
while 迴圈
理論與題目說明
機器翻譯,尚未經母語人士審閱。
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
do {
// 至少執行一次
} while (條件);
有數字就一直讀:while (in.hasNextInt()) { int x = in.nextInt(); … }。
題目。 讀入自然數 n。直到 n 變成 1:偶數就除以 2,奇數就變成 3n + 1。
輸出步數(考拉茲猜想)。