用do-while写的
class Demo
{
public static void main(String[] args)
{
int i=1;
int sum=0;
do{
if(i%2 == 1)
{
i++;
continue;
}
sum=sum+i;
i++;
}while(i<=100);
System.out.println("sum="+sum);
}
}
用while写的
class Demo
{
public static void main(String[] args)
{
int i=1;
int sum=0;
while(i<=100){
if(i%2 == 1)
{
i++;
continue;
}
sum=sum+i;
i++;
}
System.out.println("sum="+sum);
}
}
|