JAVA今日2021.8.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

posted @ 2021-08-10 21:45  Walf1234  阅读(41)  评论(0)    收藏  举报