Read in your tongue here..

Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Monday, May 26, 2014

Factorial by recursion using static method

package Rahul;
import java.util.Scanner;
public class Fact {
   
static int fact(int num)
    {
        if(num==0)
            return 1;
        else
            return(num*fact(num-1));
    }

    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter number:");
        int n=sc.nextInt();
        System.out.print("Factorial of "+n+"="+Sec.fact(n));
    }
}