java求1~100之间所有偶数的个数

要求用循环语句,不用for循环。

public class Test{

public static void main(String[] args){
//计数器
int n = 0;
int x = 100;
while(x > 0){
if(x%2 == 0)n++;
x--;
}
System.out.println("共有个"+n+"偶数");
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-12-03
public class Test{

public static void main(String[] args){
//个数
int n=0;
//每一个数
int x=1;

while(x<=100){
if(x%2==0)
n=n+1;
x=x+1;
}

System.out.println("共有个"+n+"偶数");
}
}
相似回答