斐波那契函式:f(n)=f(n-1)+f(n-2);
package XXXXX; import java.util.Scanner; public class Fbonaci斐波那契 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner n=new Scanner(System.in); int moon=n.nextInt(); System.out.print(f(moon)); } public static int f(int x) { if(x!=1&&x!=2) { if(x!=3) { int k=f(x-1)+f(x-2); return k; } return 2; } return 1; } }