流程控制语句

 

1.循环语句while

while(循环条件){
执行语句
………
}

用while打印1-100;

int i=1;
    while(i<=100){
    System.out.println(i);
    i++;
    }

 

用while打印1-100的和;

int i=0;
int count=0;
while(i<=100){
count+=i;
i++;
}
System.out.println(count);

 

用while打印1-100的偶数和;(奇数在if判断改成  i%2==1);

int i=1;
int count=0;
while(i<=100){
if(i%2==0){
count+=i;
}
i++;
}
System.out.println(count);

 

posted on 2020-04-23 09:51  嘿抬头i  阅读(109)  评论(0编辑  收藏  举报