Solve It By Java
Sunday, 29 November 2015
Recursive Factorial in Java
public class RecursiveFactorial {
public static void main(String[] args) {
System.out.println(""+factorial(5));
}
public static long factorial(long x) {
if (x == 1) return 1;
else return x * factorial(x-1);
}
}
Output :
120
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment