Factorial program in Java
import java.util.Scanner;
public class Factorial{
public static void findFactorial(int number){
int factorial=1;
do{
factorial*=number;
number--;
}while(number>=2);
System.out.println(factorial);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int number=sc.nextInt();
findFactorial(number);
sc.close();
}
}
Output: Enter the number : 4
24
Comments
Post a Comment