//非递归实现 def feb1(n:Int):ArrayBuffer[Int] = { val ab = new ArrayBuffer[Int]() if(n==0) ab += 0 else if(n==1 || n==2) ab += 1 else{ ab += (0,1,1) for(m <- 3 until n){ val thisN = ab(m-1) + ab(m-2) ab += thisN } ab } } val febTest10 = feb1(10) println(febTest10.toList) //递归实现 def feb (n:Int):Int = { if(n==0) 0 else if(n==1 || n ==2) 1 else feb(n-1) + feb(n-2) } for(n <- 0 to 10){ println(feb(n)) }