Wednesday, 18 May 2016

control statements in java

difference between while loop and dowhile loop example

 do while loop example program:
public class DoTest {

   public static void main(String args[]){
      int x =20;
   do
      {
         System.out.print("value of x : " + x );
         x++;
         System.out.print("\n");
      }

while( x < 20 );
}
}

output :


while loop example program:

public class WhileTest {

   public static void main(String args[]){
      int x =20;
   while( x < 20 )
      {
         System.out.print("value of x : " + x );
         x++;
         System.out.print("\n");
      }


}
}

output:
 


No comments:

Post a Comment