DoWhile循环

 

 

 1 package struct;
 2 
 3 public class DoWhileDemo01 {
 4     public static void main(String[] args) {
 5         int i = 0;
 6         int sum = 0;
 7         do {
 8             sum = sum + i;
 9             i++;
10         }while (i<=100);
11         System.out.println(sum);//5050
12     }
13 }
 1 package struct;
 2 
 3 public class DoWhileDemo02 {
 4     public static void main(String[] args) {
 5         int a = 0;
 6         while(a<0){
 7             System.out.println(a);
 8             a++;
 9         }
10         System.out.println("=====================");
11         do {
12             System.out.println(a);
13             a++;
14         }while (a<0);
15     }
16 }

 

posted on 2022-07-21 16:24  一枚努力学习的小白  阅读(20)  评论(0编辑  收藏  举报