- Today
- Total
Notice
Recent Posts
Codemental
[baekjoon][Java] 10870번 - 피보나치 수 5 본문
반응형
문제
제출답안 (2022.07.22)
import java.io.*;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
br.close();
if(N == 0 ) {
System.out.println(0);
}else if( N ==1 ) {
System.out.println(1);
}else {
System.out.println(fibonacci(2, N, 0, 1));
}
}
public static int fibonacci(int curN, int N, int beforeVal1, int beforeVal2) {
if(curN == N ) {
return beforeVal1 + beforeVal2;
}else {
return fibonacci(curN+1, N, beforeVal2, beforeVal1 + beforeVal2);
}
}
}
채점결과 (2022.07.22)
'Java > 코딩테스트(baekjoon)' 카테고리의 다른 글
[baekjoon][Java] 17478번 - 재귀함수가 뭔가요? (0) | 2022.07.22 |
---|---|
[baekjoon][Java] 10872번 - 팩토리얼 (0) | 2022.07.22 |
[baekjoon][Java] 15596번 - 정수 N개의 합 (0) | 2022.07.22 |
[baekjoon][Java] 11021번 - A+B - 7 (0) | 2022.07.22 |
[baekjoon][Java] 2742번 - 기찍 N (0) | 2022.07.22 |