เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Initialize an array

Once parameterized, initializing the array is done by passing in the desired data inside parentheses ((___)). This contrasts with square brackets ([___]), like in programming languages like Java and Python. Arrays in Scala are zero-indexed.

In this exercise, you'll initialize the hands array you created and parameterized in the previous exercise with the starting hand (i.e., first two cards) for each player. The card variables you need are already defined (they are all of type Int).

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Scala

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Initialize the first player's hand in the hands array.
  • Initialize the second player's hand in the hands array.
  • Initialize the third player's hand in the hands array.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

// Create and parameterize an array for a round of Twenty-One
val hands: Array[Int] = new Array[Int](3)

// Initialize the first player's hand in the array
___(___) = tenClubs + fourDiamonds

// Initialize the second player's hand in the array
___(___) = nineSpades + nineHearts

// Initialize the third player's hand in the array
___(___) = twoClubs + threeSpades
แก้ไขและรันโค้ด