第5章——循环结构——while循环累加:1~50中7的倍数之和

知识点:

             1、累加简写:

                             c += a;// c+=a是c=c+a的简写;

             2、while循环:

                                    while(循环条件){

                                                                     代码块

package b第五章__循环结构;

//1~50中7的倍数之和,注意:7的倍数包括7
public class Bi {
    public static void main(String[] args) {
        int a = 0;// 定义变量a
        int b = 0;
        int c = 0;
        while (a <= 50) {// 定义条件a<50
            ++a;
            if (a % 7 == 0) {// 定义条件选项:1到50中7的倍数

                c += a;// c+=a是c=c+a的简写

            }
        }
        System.out.println(c);

    }
}

 

                                                                   }

posted @ 2021-01-06 10:36  綦君  阅读(625)  评论(0)    收藏  举报