달력

02

« 2012/02 »

  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  •  
  •  
  •  
/**
 * Factorial 를 재귀적 함수 형태로 구현한다. 
 */
package net.wiseant.test.algorithm.number;

/**
 * @author Sang-Hyup Lee
 * @version 1.0
 *
 */
public class FactorialRecursive {

 int res;
 int factorial(int n) {
  if ( n <= 1 )
   res = 1;
  else
   res = n * factorial(n-1);
  
  // System.out.print("print_1 : " + res + ", ");
  
  return res;
 }
 
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  FactorialRecursive obj = new FactorialRecursive();
  
  int temp;
  temp = obj.factorial(5);
  
  System.out.println("end_of_program : " + temp);
 }

}
Posted by korcslewis