public class views { public static void main(String arg[]){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); int s=0; s=Fibonacci(n); System.out.println(s); } public static int Fibonacci(int n) { if(n < 0){ return 0; } if(n == 0){ return 0; } if(n == 1){ return 1; } return Fibonacci(n-1)+ Fibonacci(n-2); } }
运用递归的思想,和静态方法的调用