feat:ChatGPT第 3 课:函数对象、匿名函数、=>、map
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package practise3.exercises
|
||||
|
||||
/*练习 5:使用 filter
|
||||
|
||||
给你:
|
||||
val nums = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
||||
|
||||
使用 filter,只保留偶数:
|
||||
List(2, 4, 6, 8, 10)
|
||||
|
||||
提示:
|
||||
x % 2 == 0*/
|
||||
object Exercises5 {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val nums = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
||||
val result = nums.filter(x => x % 2 == 0)
|
||||
println(result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user