import java.util.Scanner;
class Factorial{
public static void main(String args[]){
System.out.println("Enter the number: ");
Scanner s = new Scanner(System.in);
int a = s.nextInt();
int result= fact(a);
System.out.println("Factorial of the number is: " + result);
}
public static int fact(int b)
{
if(b <= 1)
return 1;
else
return b * fact(b-1);
}
}
No comments:
Post a Comment