while迴圈語句

2021-09-01 14:34:09 字數 750 閱讀 6154

例子如下:

public static void main(string args) 

* 表示式滿足就執行迴圈體,直到不滿足條件就跳出迴圈

*//*

* 分別求出1~200之間的奇數之和,偶數之和

*/int i=1,sum=0,sum1=0;

while(i<201)

if(i%2==0)

i++;

} system.out.println("1~200之間的奇數和為:"+sum);

system.out.println("1~200之間的偶數和為:"+sum1);

/** do{}while();

* 至少會執行一次!!!!

*//*do

if(i%2==0)

i++;

}while(i<201);

system.out.println("1~200之間的奇數和為:"+sum);

system.out.println("1~200之間的偶數和為:"+sum1);

*/

/* * *

* **

* ***

* ****

* *****

*/int a = 1;

while(a<6)

while(b0)

while(gsystem.out.println();

t++;

}}

while迴圈語句

案例 珠穆朗瑪峰 完整格式 初始化語句 while 條件判斷語句 執行初始化語句 執行條件判斷語句,看其結果是true還是false 如果是true,繼續執行 如果是false,結束迴圈 執行迴圈體語句 執行條件控制語句 回到2繼續 需求 世界上最高山峰是珠穆朗瑪峰 8844.43m 8844433...

while迴圈語句

計算輸出1 2 3 100的所有數字的相加和n 1s 0 while n 101 s s n n n 1 print s 計算輸出1 2 3 4 5.99的所有數字的和n 1s 0 while n 100 temp n 2 if temp 0 s s n else s s n n n 1 print...

迴圈語句 while

格式 while 條件 迴圈體 無限迴圈 終止迴圈 1 改變條件,使其不成了 2 break 中斷迴圈 死迴圈while true print 我們不一樣 迴圈100次 count 1 flag true while flag print count count 1 if count 100 fla...