public class Fibonacci {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please fill in :");
System.out.print("value = ");
int m = scanner.nextInt();
System.out.println("Fibonacci Number: " + fib(m));
}
private static int fib(int m) {
if(m==1 || m==2 )
return 1;
else if(m==0) return 0;
else return fib(m-1)+fib(m-2);
}
}
沒有留言:
張貼留言