This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kr.opid.recusive; | |
public class Fibonacci { | |
public static void main(String[] args) { | |
System.out.println(fibo(1)); | |
System.out.println(fibo(2)); | |
System.out.println(fibo(3)); | |
System.out.println(fibo(4)); | |
System.out.println(fibo(5)); | |
} | |
static int fibo(int n) { | |
if (n == 0) { | |
return 0; | |
} else if (n == 1) { | |
return 1; | |
} else { | |
return (fibo(n - 2) + fibo(n - 1)); | |
} | |
} | |
} |
'대학 생활 > JAVA' 카테고리의 다른 글
[JAVA] 이진탐색(Binary Search) (0) | 2015.11.27 |
---|---|
[JAVA] 기수정렬(RadixSort) (0) | 2015.11.20 |
[JAVA] 퀵정렬(QuickSort) (0) | 2015.11.06 |
[JAVA] 딕스트라 최단경로(Dijkstra Shortest Paths) (0) | 2015.10.31 |