Updating arrays
Since arrays are mutable, the elements in them can be updated.
In the context of Twenty-One, this could mean adding to an element in the array if that player chooses to hit to get closer to 21.
In this exercise, you'll do just that. The card variables you need are already defined, as well as the hands array you created, parameterized, and initialized previously.
If you run the code more than once, you will keep adding to hands since arrays are mutable. Your final result will then be different from the expected solution. Reloading the page will reset the hands array.
이 연습은 강의의 일부입니다
Introduction to Scala
연습 안내
- Add a
fiveClubsto the first player's hand inhands. - Add a
queenSpadesto the second player's hand inhands. - Add a
kingClubsto the third player's hand inhands.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
// Initialize player's hand and print out hands before each player hits
hands(0) = tenClubs + fourDiamonds
hands(1) = nineSpades + nineHearts
hands(2) = twoClubs + threeSpades
hands.foreach(println)
// Add 5♣ to the first player's hand
___ = ___ + ___
// Add Q♠ to the second player's hand
___ = ___ + ___
// Add K♣ to the third player's hand
___ = ___ + ___
// Print out hands after each player hits
hands.foreach(println)