public class DiGui public static void main(String[] args) System.out.println(fib(30)); } public static int fib(int n) if (n == 1 || n == 2) return 1; } else return fib(n - 1) + fib(n - 2); } }} public static void main(String[] args) int x = 0; int y = 1; int z = 0; for (int i = 2; i z = x + y; System.out.println("x = " + x + "\ty = " + y + "\tz = " + z); x = y; y = z; } }额,这个规律不是很明显吗,第一位数加第二位数就等于地三位数,也就是前2位数之和了,比如0+1=1;1+1 = 2;1+2=3;2+3=5;。。。。public class fibonacci public static void main(string[] args) //初始化变量 int n0 = 1, n1 = 1, n2; system.out.print(n0 + " " + n1 + " "); //引入for循环依次执行三个表达式,限定i的取值范围为<10 for (int i = 0; i < 10; i++) //下一个数是早先的两个数的和 n2 = n1 + n0; system.out.print(n2 + " "); //早先的第一个数成为早先的第二个数 n0 = n1; //同时当前的数成为早先的数 n1 = n2; // and current number becomes previous}system.out.println(); // terminate the line}}