Java program to explain the use of Do while loop.

Use Of DO---WHILE loop In JAVA.




JAVA Code :) 





import java.util.Scanner;


public class DoWhile


{


public static void main(String[] args)


{


  int n,ch,answer;


  Scanner sc = new Scanner(System.in);


do


{


System.out.print("Enter a number:");


n=sc.nextInt();


answer=n*n;


System.out.println(+answer);


System.out.println("***Do you want to continue:-\n if YES Enter-1 and if NO Enter any number****");


System.out.print("\nEnter your choice:");


ch=sc.nextInt();


} while(ch==1);


System.out.println("***END of Your Program***");


sc.close();


}


}



INPUT and OUTPUT :)



Post a Comment

0 Comments