JAVA今日2021.8.6

JAVA while循环

while循环结构

while(布尔表达式){
    //循环内容
}

while01

package JAVASE.struct;

public class while01 {
    public static void main(String[] args) {
        //输出1-100
        int i = 0;
        while (i<100){
            i++;
            System.out.println(i);
        }
    }
}

while02

package JAVASE.struct;

public class while02 {
    public static void main(String[] args) {
        //1+2+3+...+100=
        int i = 0;
        int s = 0;
        while (i<100){
            i++;
            s = s+i;
        }
        System.out.println(s);
    }
}

2021.8.6

posted @ 2021-08-06 22:49  Walf1234  阅读(35)  评论(0)    收藏  举报