获得徽章 0
- object test4 {
def main(args: Array[String]): Unit = {
val scores = Array(100, 51, 55, 67, 59, 89)
val newScores = scores.map(score => if (score >= 56 && score <= 59) 60 else score)
println(newScores.mkString(", "))
}
}展开赞过评论2 - object test3 {
def main(args: Array[String]): Unit = {
val fibSeries = fibonacci(20)
fibSeries.foreach(println)
}
def fibonacci(n: Int): Array[Int] = {
if (n <= 0) {
Array()
} else {
val arr = new Array[Int](n)
arr(0) = 1
if (n > 1) {
arr(1) = 1
for (i <- 2 until n) {
arr(i) = arr(i - 1) + arr(i - 2)
}
}
arr
}
}
}展开赞过评论3
![[呲牙]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_2.cd1e2bd.png)