Factorial program using recursion in java

 Java program for factorial using recursion
public class factorial {
    int fact(int n){
        if (n==1) {
            return 1;
        }
        else {
            return (n*fact(n-1));
        }
    }
    public static void main(String[] args) {
        factorial obj=new factorial();
        System.out.println(“fact=”+obj.fact(4));
    }
}

Leave a Reply

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

7 + 1 =