如何使用while循环实现100之内偶数输出,并求和?

package cn.kgc;

public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		/*1.初始化条件
		 *2.循环条件
		 *3.迭代条件
		 *4.循环体
		 *
		 *①
		 *while(②){
		 *   ④
		 *   ③
		 *
		 *}
		 * 
		 * */
		/*int count=1;
		while(count<=50){
			System.out.println("count");
			//count++;
			
		}*/
		
		//100以内的偶数的输出,以及和
		int i=1;
		int sum=0;
		while(i<=100){
			if(i%2==0){
				System.out.println(i);
				sum=sum+i;
				//sum+=i;
			}
			
			i++;
			
		}
		
		System.out.println(sum);
		System.out.println(i);
	}

}
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
2550
101
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值