import java.util.*; public class FactDoWhile { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("\n Enter Number..."); int number = s.nextInt(); int fact=1,i=1; do { fact=fact*i; i++; }while(i<=number); System.out.println("\n Factorial of "+number+" is = "+fact); } } Output: Enter Number... 6 Factorial of 6 is = 720
No comments:
Post a Comment
If you have any doubts, please let me know