Factorial Program in Java
Factorial is the product of all positive integers less than or equal to n. Examples: 4! = 4 × 3 × 2 × 1 = 24
import java.util.Scanner;
public class Factorial
{
public static void main(String[] args)
{
// TODO code application logic here
int n,
fact = 1;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of series=");
n = sc.nextInt();
for (int i = 1; i <= n; i++)
{
fact = fact * i;
}
System.out.println("Factorial=" + fact);
}
}
Output:
Enter number of series=5 Factorial=120
Frequently Asked Questions
What is Factorial Program ?
Factorial is the product of all positive integers less than or equal to n. Examples: 4! = 4 × 3 × 2 × 1 = 24
What is Factorial Program in Java?
Factorial is the product of all positive integers less than or equal to n. Examples: 4! = 4 × 3 × 2 × 1 = 24