do while循环

循环结构

do while循环

 

 

 

package base.struct;

public class DoWhileDemo1 {
  public static void main(String[] args) {
      //计算1+2+3+。。。。+100,使用do while
      int i=0;
      int sum=0;
      do {
          sum=sum+i;
          i++;
      }while(i<=100);
      System.out.println(sum);
  }
}

 

package base.struct;

public class DoWhileDemo2 {
  public static void main(String[] args) {
      //while和do while最主要的区别就是while先判断后执行,dowhile先执行后判断
      int a= 0;
      while (a<0){
          System.out.println(a);
          a++;
      }
      System.out.println("====================");
      do {
          System.out.println(a);
          a++;
      }while (a<0);
  }
}
 
posted @ 2022-05-13 16:39  怎样的人生  阅读(67)  评论(0)    收藏  举报