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 result;
if(n < 2) {
result = 1;
} else {
result = Fibonacci(n-1) + Fibonacci(n-2);
}
return result;
}
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