Last active
August 8, 2018 07:41
-
-
Save leehs99/da6cd4d24003864f3191e4f30f13dd19 to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.Scanner; | |
//Object : 피보나치수 | |
//question : n이 주어졌을 때, n번째 피보나치 수를 구하는 프로그램을 작성하시오.(피보나치 수= Fn=Fn-1+Fn-2) 단, n<45 | |
//Email : 99leehs@naver.com | |
public class Main2747 { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
System.out.println(Fibo(n)); | |
} | |
public static int Fibo(int n) { | |
if(n==0) { | |
return 0; | |
} else if(n==1) { | |
n +=1; | |
return 1; | |
}else { | |
return Fibo(n-1)+Fibo(n-2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment