6. แยกย่อย

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 6-21  เมท็อดหาจำนวนฟิโบนักชี (แบบเรียกซ้ำ)
public static int fib(int n) {
  if (n < 0) throw new IllegalArgumentException(n + " เป็นลบ");
  if (n <= 1) return n;
  return fib(n-1) + fib(n-2);
}
©2009 S.Prasitjutrakul