Java小程序2(2015-8-10)

/*
while语句的使用、讲解
*/
public class Test1{
 public static void main(String[] args){
  int number = 10;
  //--循环条件
  while(number>0){
   //--循环体:循环执行的语句
   System.out.println(number);
   //--条件的变化
   number--;
  } 
 }
}

/* do-while的讲解使用 */ public class Test2{  public static void main(String[] args){   int number = 10;

  do{    System.out.println(number);

   number--;

  }while(false);

  while(false){    //==循环体   }

 } }

1、使用do-while单循环,打印输出10~100之间所有

public class Test22{      

public static void main(String [] args){                     

              System.out.println("10-100之间能同时被5和9整除的整数有:");

              int a=10;         

   do{                

               if(a%5==0&&a%9==0){              

                             System.out.println(a);}                                  

                             a++;

           }while(a<=100);            

            /*  System.out.println("10-100之间能同时被5和9整除的整数有:");

            int a=10;          

             while(a<=100)           {               

                         if(a%5==0&&a%9==0){             

                                          System.out.println(a);}                                

                          a++;

           }*/

  }}

能同时被5和9整除的整数。

原文地址:https://www.cnblogs.com/Ly426/p/4717818.html