Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import java.util.Scanner;
public class FibonacciNumber {
public static int Fibonacci(int n) {
int[] fib = new int[50];
fib[0] = fib[1] = 1;
for(int i = 2; i <= n; i++) {
fib[i] = fib[i-1] + fib[i-2];
}
return fib[n];
}
public static void main(String[] args) {
System.out.print("第何項を求めますか:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("fib(" + n + ") = " + Fibonacci(n));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment