面试题:用10种方法实现1,1,2,3,5,8,13,21...序列的程序(已实现两种),答对加分(JAVA)
public class Main { /** * @param args */ public static void main(String[] args) { //1,1,2,3,5,8,13,21 int[] n = new int[8]; n[0] = 1; n[1] = 1; n[2] = 2; for(int i=1; i<7; i++) { n[i+1] = n[i-1] + n[i]; } for(int i : n) { System.out.println(i); } //1,1,2,3,5,8,13,21 int m = 0; int x = 1; int y = 1; for(int i=1; i<7; i++) { m = x + y; x = y; y = m; System.out.println(m); } }}其实这是一个公司出的面试题,如果做出来的话,月薪8000