Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by awhfasjd ( 6 years ago )
//import your library
import java.util.Scanner;

public class Solution {
    /**
     * calculate the nth number in the fibonacci array.
     * @param n stt of the number
     * @return it's fibonacci value
     */
    public int fibonacci(int n) {
        if (n == 0 || n == 1) {
            return n;
        } else {
            return fibonacci(n - 1) + fibonacci(n - 2);
        }
    }

    /**
     * this is the main so why the heck it needs a javadoc cmt.
     * @param args tham so dau vao
     */
    public static void main(String[] args) {
        Solution n = new Solution();
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        System.out.println(n.fibonacci(num));
    }
}

 

Revise this Paste

Children: 109987
Your Name: Code Language: