累了,写点简单的。
1 public class hello { 2 3 /** 4 * @param args 5 */ 6 public static void main(String[] args) { 7 int Fabnum = 10; 8 int sum = 0; 9 System.out.print("Serial:\t"); 10 for(int i = 1; i <= Fabnum; i++) 11 { 12 System.out.print(i + "\t"); 13 } 14 System.out.println(); 15 System.out.print("Fabnum:\t"); 16 for(int i = 1; i <= Fabnum; i++) 17 { 18 System.out.print(Fab(i) + "\t"); 19 } 20 } 21 static int Fab(int i) 22 { 23 int result; 24 if (i == 1 || i == 2){ 25 result = 1; 26 }else{ 27 result = Fab(i-1) + Fab(i - 2); 28 } 29 30 return result; 31 } 32 33 }