Factorial in java

 Today we are discussing about factorial in java


factorial say that:
                             factorial is a function that multiplies a number by every number below it. For example 5!= 5*4*3*2*1=120. The function is used, among other things, to find the number of way “n” objects can be arranged.

Now we know the concept of factorial So we are able to write a program of factorial in java.




package com.ritesh;

import java.util.Scanner;

public class factrioal{
public static void main(String[] args) {
fact();


}

static void fact()
{
System.out.println("Enter a number");
Scanner sc=new Scanner(System.in);
long num= sc.nextLong();
long fact=1;

long i;
for(i=num; i>=1; i--)
{
fact *=i;



}
System.out.println(fact);


}
}



Comments