Call a function
Now it's time to actually use a function! As a reminder, here is the maxHand function that finds the maximum hand value between two hands (ignoring whether or not each hand busts):
def maxHand(handA: Int, handB: Int): Int = {
if (handA > handB) handA
else handB
}
In this exercise, you'll create a variable to add the cards in each hand together, then call maxHand and pass in those variables as arguments to determine the maximum hand value. The maxHand function and the card variables you need are already defined.
이 연습은 강의의 일부입니다
Introduction to Scala
연습 안내
- Calculate the hand value for
playerA, who has the following cards:queenDiamonds,threeClubs,aceHearts(worth 1),fiveSpades. - Calculate the hand value for
playerB, who has the following cards:kingHearts,jackHearts. - Call the
maxHandfunction, passing inhandPlayerAandhandPlayerBas arguments. Pass this function call into theprintlnfunction to print out the maximum hand value.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
// Calculate hand values
___ handPlayerA: ___ = ___
___ handPlayerB: ___ = ___
// Find and print the maximum hand value
___(___(___, ___))