(1).while程序练习
package com.ccy.demo;
public class Dome7 {
public static void main(String[] args) {
/**
*打印1-100的数字
*/
int a2 = 0;
while (a2 < 100)
{
a2++;
System.out.println(a2);
}
/**
* 打印1-100的偶数
*/
int a = 1;
while (a <=100)
{
if(a %2==0)
{
System.out.println("1-100的偶数是:"+a);
}
a++;
}
/**
* 打印1-100偶数个数之和
*/
int a1 = 1;
int b1 =0;
while (a1 <= 100){
if (a1 %2 ==0)
{
b1+=1;
}
a1++;
}
System.out.println("1-100偶数个数之和为:"+b1);
/**
* 打印1-100偶数之和
*/
int c = 1;
int d = 0;
while (c<=100){
if (c %2 == 0)
{
d += c; // b = b+1;
}
c++;
}
System.out.println("1-100偶数之和为:"+d);
}
}