자바의 제귀

C/Java : 2007. 11. 6. 14:24
public class FactorialRecursive {
 public static int factorial(int n) {
  if(n == 1) return 1;            //n이 1이 되면 1을 반환한다.
  return n*factorial(n-1);     //아니면 (n-1)로 재귀
 }
 
 public static void main(String[] args) {
  System.out.println("5 factorial = " + factorial(5));
 }
}
Posted by 청웨일