JAVA循环结构
一.while循環(huán)
while(布爾表達式)
{
//代碼語句
}
和C#一致
?
二.do...while..循環(huán)
do{
代碼語句 }while(布爾表達式)
在判斷條件之前已經(jīng)執(zhí)行的代碼語句,如果布爾表達式為true,則重復執(zhí)行代碼語句,直到布爾表達式為false.
如果布爾表達式為false,則只執(zhí)行一遍代碼語句.
?
三.for 循環(huán)
for(初始條件;循環(huán)條件;狀態(tài)改變)
{循環(huán)體,代碼語句}
和C#一致
?
四.遍歷(java增強for循環(huán))
public class Test {public static void main(String args[]){int [] numbers = {10, 20, 30, 40, 50};for(int x : numbers ){System.out.print( x );System.out.print(",");}System.out.print("\n");String [] names ={"James", "Larry", "Tom", "Lacy"};for( String name : names ) {System.out.print( name );System.out.print(",");}} }輸出結果:
10,20,30,40,50,
James,Larry,Tom,Lacy,
?
轉載于:https://www.cnblogs.com/zhangxin4477/p/7473957.html
總結
- 上一篇: 记一次使用快速幂与Miller-Rabi
- 下一篇: css实现倒8字效果