Skip to content

Instantly share code, notes, and snippets.

@leehs99
Last active August 8, 2018 07:41
Show Gist options
  • Save leehs99/da6cd4d24003864f3191e4f30f13dd19 to your computer and use it in GitHub Desktop.
Save leehs99/da6cd4d24003864f3191e4f30f13dd19 to your computer and use it in GitHub Desktop.
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