while
1 public class TestWhile { 2 3 /** 4 * 测试循环 5 */ 6 public static void main(String[] args) { 7 int a=1; 8 while(a<=100){ 9 System.out.println(a); 10 a++; 11 } 12 System.out.println("while循环结束了 "); 13 //1+2+3+4+5....+100=? 14 int b=1; 15 int sum=0; 16 while(b<100){ 17 //sun+=b; 18 sum=sum+b; 19 b++; 20 } 21 System.out.println("从1加到100的和是:"+sum); 22 23 } 24 }
posted on 2017-09-28 21:40 PoeticalJustice 阅读(144) 评论(0) 编辑 收藏 举报