Define mutable variables (var)
Scala has two kinds of variables: val and var. var are mutable and can be reassigned.
In Twenty-One, an ace is like a var, as it can be worth 1 or 11 points depending on the player's choice (as opposed to cards 2 through king, which have a constant point value throughout the game).
In this exercise, you will define each ace as a var of type Int set to a default value of 1 point. This time around, you'll leverage Scala's type inference (its ability to guess types based on supplied values) and omit the type annotation.
Bài tập này là một phần của khóa học
Introduction to Scala
Hướng dẫn bài tập
- Define four mutable variables, all of type
Intand equal to 1:aceClubs,aceDiamonds,aceHearts,aceSpades.
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.
// Define mutable variables for all aces