While循环

 

 

 1 package com.lin.struct;
 2 
 3 public class WhileDemo1 {
 4     public static void main(String[] args) {
 5         //输出1~100
 6         int i = 0;
 7         while (i<100){
 8             i++;
 9             System.out.println(i);
10         }
11     }
12 }
 1 package com.lin.struct;
 2 
 3 public class WhileDemo2 {
 4     public static void main(String[] args) {
 5         //死循环
 6         while (true){
 7             //等待客户连接
 8             //定时检查
 9             //。。。。。。
10         }
11 
12     }
13 }
 1 package com.lin.struct;
 2 
 3 public class WhileDemo3 {
 4     public static void main(String[] args) {
 5         //计算1+2+3+...+100=?
 6         int i =0 ;
 7         int sum =0 ;
 8         while (i<=100){
 9             sum =sum+i;
10             i++;
11         }
12         System.out.println(sum);
13     }
14 }

 

posted @ 2021-02-12 21:43  奔啵儿灞  阅读(53)  评论(0)    收藏  举报