컴공 공부/백준

[백준 알고리즘] 10870 피보나치5 자바

무무뭉? 2021. 1. 29. 12:25



import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
 
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		in.close();
		
		int sum = fib(N);
		System.out.println(sum);
		
	}
	
	public static int fib(int N) {
		if(N < 1) return 0;	// 재귀 종료조건
		else if(N==1) return 1;
		return fib(N - 1)+ fib(N-2);		
	}
 
}