09 April 2012

Calculate Factorial of a Number using Recursion




import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class FactorialUsingRecursion {
public static void main(String args[]) throws NumberFormatException, IOException{
System.out.println("Enter the number: ");
BufferedReader br=
new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());
int result= fact(a);
System.out.println("Factorial of the number is: " + result);
}
static int fact(int b)
{
if(b <= 1)
return 1;
else
return b * fact(b-1);
}
}

1 comments:

Naviya Nair said...

I have read your blog its very attractive and impressive. I like it your blog.

Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

Post a Comment

Related Posts with Thumbnails

Popular Posts

 
;