Java program to calculate factorial of integer using recursion
public class Factorial
{
public int fact(int n) {
if(n==1) {
return 1;
}
else {
return fact(n-1) * n;
}
}
public static void main(String args[]){
int number =4;
Factorial factorial = new factorial();
System.out.println("The factorial of the number is : " + factorial.fact(number);
}
}
No comments :
Post a Comment