Java examples for Object Oriented Design:Method Recursive
Classic Factorial with recursive solution
public class Main { public static void main(String[] args) { int n = 5;/*from w ww .j a v a 2 s . c om*/ long fact; fact = factorial(n); System.out.println("The factorial of " + n + " is " + fact + "."); } private static long factorial(int n) { if (n == 1) return 1; else return n * factorial(n - 1); } }