Bắt đầu ngayBắt đầu miễn phí

Initialize a list using cons and Nil

You just initialized the prizes list like this:

val prizes = List(10, 15, 20, 25, 30)

That's works great! There's also another commonly used technique that combines the cons (::) operator and Nil, which is the empty list.

In this exercise, you'll initialize the same prizes list from last exercise, just using this fancy, efficient shorthand.

Bài tập này là một phần của khóa học

Introduction to Scala

Xem khóa học

Hướng dẫn bài tập

  • Using :: and Nil, initialize a list named prizes with an element each round's prize, where the first through fifth round's prizes are 10, 15, 20, 25, and 30, respectively.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

// Initialize a list with an element each round's prize
val prizes = ___
println(prizes)
Chỉnh sửa và Chạy Mã