Java Recursion Program Practise 1 - Factorial

Java Program to find Factorial of given number using Recursion

Output


import java.util.*;

class Main {

    

    int fact(int n){

        if(n==0)

        return 1;

        else{

            return(n*fact(n-1));

        }

    }

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int a;

        System.out.println("Enter a number to get the factorial with the help of recursion");

        a = in.nextInt();

        Main ob = new Main();

       System.out.println(ob.fact(a));

        

        

        

    }

}

Comments

Translate

Popular posts from this blog

Letter to SBI Bank Manager of Local Branch to reduce the interest rate on home loan

"No other subject taught in school is as important as Moral Science." Express your views for or against this statement

Narrate an experience that shows appearances can be deceiving

Java Recursion Program Practise 2 - Fibonacci Series

Java String Manipulation 28th Jan Practice 1 - to accept a character and check whether it is a letter or not. If letter, then convert it to uppercase or lowercase. Also check whether it is letter or a special character

Macbeth Personal Notes: Act 1 Scene 2

Java Recursion Program Practise 5 - to input a number and print the sum of digits of the number

Java String Manipulation 28th Jan Practice 2 - input a string and check whether it is a palindrome or not

Abhisara - the Tryst Notes