Write a Java Program to find Factorial using While loop
Factorial of any number is the product of an integer and all the integers below it
For example :: factorial of 5 is 5! =5* 4 * 3 * 2 * 1 = 120.
In below source code i will show you how to Write a Java program to find factorial using while loop.
SOURCE CODE ::
import java.util.Scanner; public class Factorial{ public static void main(String[] args) { int n, fact=1; Scanner sc = new Scanner(System.in); System.out.println("Enter any number :"); n=sc.nextInt(); int i=1; while(n>=i) { fact=fact*i; i++; } System.out.println("Factorial is :" +fact); } }
OUTPUT ::
Enter any number : 9 Factorial is :362880