JAVA今日2021.8.10
阿新 • • 發佈:2021-08-10
JAVA For迴圈增強
For迴圈增強結構
for(宣告語句:表示式)
{
//程式碼語句
}
for05
package JAVASE.struct; public class for05 { public static void main(String[] args) { int[] numbers = {10,20,30,40,50};//定義了一個數組 for (int i = 0; i < 5; i++) { System.out.println(numbers[i]); } System.out.println("============"); //簡化上述for迴圈 for (int x:numbers){ System.out.println(x); } } }
JAVA break and continue
break
package JAVASE.struct; public class break0 { public static void main(String[] args) { int i = 0; while (i<100){ i++; System.out.println(i); if (i==30){ break;//用於退出迴圈 } } } }
continue
package JAVASE.struct; public class continue0 { public static void main(String[] args) { int i = 0; while (i<100){ i++; if (i%10==0){ System.out.println(); continue;//用於跳過指定步驟 } System.out.print(i+"\t"); } } }
2021.8.10