Java do while loop output number from 1 to 10

Question

We would like to use do while loop to output number from 1 to 10.

public class Main 
{  /*from w  ww.  j av  a2 s . co m*/
   public static void main(String[] args)
   {
      int counter = 1; 

      //your code

      System.out.println(); 
   } 
}



public class Main 
{  
   public static void main(String[] args)
   {
      int counter = 1; 

      do 
      {
         System.out.printf("%d  ", counter);
         ++counter;
      } while (counter <= 10); // end do...while 

      System.out.println(); 
   } 
}



PreviousNext

Related