The factorial of a positive integer n is equal to 1*2*3*…n. You will learn to calculate the factorial of a number using for loop in this example. This program takes a positive integer from the user and computes factorial using for loop.

// factorial a number
import java.util.Scanner;
class factorial 
	public static void main(String[] args) 
		System.out.println("Enter the number:");
		Scanner s=new Scanner(;
		int a=s.nextInt();
		int b=a,sum=1;
		for(int i=1;i<=a;i++)
(Visited 13 times, 1 visits today)

Written by:

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »