Page 557 - AP Computer Science A, 7th edition
P. 557

the temporary ArrayList
Set cards to the temporary ArrayList
Here is the method that implements this algorithm.
Line 1:
Line 2:
Line 3:
Line 4:
Line 5:
Line 6:
Line 7:
Line 8:
Line 9:
Line 10:
Line 11:
public void shuffle() {
int size = cards.size();
List<Card> temp = new ArrayList<Card>(); for (int j = 1; j < size; j++)
{
int index = (int) (Math.random() ∗ size);
temp.add(cards.get(index)); }
cards = temp; }
The method does not work as intended. Which of the following changes to shuffle would ensure that it works correctly?
Replace Line 5 with I
for (int j = 0; j < size; j++)
Replace Line 7 with










































































   555   556   557   558   559