Blue___
코딩배우는 학생🌎
Blue___
전체 방문자
오늘
어제
  • 코딩배우는 학생🧀 (242)
    • Algorithms (145)
      • BOJ[Java] (107)
      • Programmers[Java] (32)
      • Coding_Contest (3)
    • Web (22)
      • .NET Core C# (2)
      • Java (1)
      • Oracle SQL (7)
      • Web-ProJect (3)
      • Error처리 (1)
      • Web지식 (4)
      • Javascript (1)
      • Vue (3)
    • Git (4)
    • Java_beginner(Repl.it) (55)
      • Auto-Graded-Course(AP CS A) (54)
    • 프로젝트 직딩일기 (3)
    • Hanyang_Assignment (0)
    • 이모저모 (4)
      • 잡담 (1)
      • 2021 오픈소스 컨트리뷰터 아카데미 (1)
      • DDD - 6기! (1)
    • 북리뷰 (1)
      • 리팩토링 2판 (1)
      • 클린코드 (0)

블로그 메뉴

  • 🐰GITHUB
  • ☘️포트폴리오
  • 🌸MBC개발_투표 2022
  • 🍭MBC_APP

공지사항

인기 글

태그

  • programmers
  • 프로그래밍
  • AP CS A
  • algorithm
  • 레플릿
  • 코딩배우는학생
  • java basic
  • Bakjoon
  • auto-graded course
  • 자바
  • coding
  • 코딩
  • Java tutorial
  • 코딩배우는 학생
  • 프로그래머스
  • 알고리즘
  • 백준
  • Java
  • repl.it
  • REPL

최근 댓글

최근 글

티스토리

hELLO
Blue___

코딩배우는 학생🌎

032 - For Loop Challenge 1 (optional)
Java_beginner(Repl.it)/Auto-Graded-Course(AP CS A)

032 - For Loop Challenge 1 (optional)

2019. 12. 7. 21:50

The fibonacci sequence is a sequence of numbers in which the next number is the sum of the previous two numbers.

 

The first two numbers of the fibonacci sequence are 0, 1.

 

The first 8 numbers of the fibonacci sequence are 0, 1, 1, 2, 3, 5, 8, 13

 

Write some code to print out the first X numbers of the fibonacci sequence.

 

Your output should be on one line, with each number separated by a space. You may assume that x is at least 2.

 


Solution

Recursion basic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Scanner;
 
class Bakjoon {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);
        System.out.print("In:");
        int x = inp.nextInt();
        //write your code below
        for(int i=0;i<x;i++) {
            System.out.print(Fibonacci(i)+" ");
        }
    }
     public static int Fibonacci(int n) {  
         if(n==0){
             return 0;
         }
         else if(n <= 2) 
             return 1;
         else
             return Fibonacci(n-1) + Fibonacci(n-2);
     }
}
 
 
 

 

반응형
저작자표시 (새창열림)

'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글

034 - Big Number Program (From Decoding)  (0) 2019.12.10
033 - For Loop Challenge 2 (optional)  (0) 2019.12.07
031 - Further For Loop Practice 7 (mIxEd CaSe)  (0) 2019.12.07
030 - Further For Loop Practice 6 (reverse string)  (0) 2019.12.07
029 - Further For Loop Practice 5 (printing characters)  (0) 2019.12.07
    'Java_beginner(Repl.it)/Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
    • 034 - Big Number Program (From Decoding)
    • 033 - For Loop Challenge 2 (optional)
    • 031 - Further For Loop Practice 7 (mIxEd CaSe)
    • 030 - Further For Loop Practice 6 (reverse string)
    Blue___
    Blue___
    완전 연소한 불은 재를 남기지않는다 : 코딩배우는학생 🌎

    티스토리툴바