February 2014
Beginner
1248 pages
62h 25m
English
Method shuffle (lines 30–46) shuffles the Cards in the deck. The method loops through all 52 Cards (array indices 0 to 51). For each Card, a number between 0 and 51 is picked randomly to select another Card. Next, the current Card object and the randomly selected Card object are swapped in the array. This exchange is performed by the three assignments in lines 42–44. The extra variable temp temporarily stores one of the two Card objects being swapped. The swap cannot be performed with only the two statements
deck[first] = deck[second];deck[second] = deck[first];
If deck[first] is the "Ace" of "Spades" and deck[second] is the "Queen" of "Hearts", after the first assignment, both array ...
Read now
Unlock full access