What does the following code compute?
int num = 0;
for(int j = 0; j < 1000; j++)
{
c.flip( );
if(c.isHeads()) num++;
}
double value = (double) num / 1000;
1) the number of Heads flipped out of 1000 flips
2) the number of Heads flipped in a row out of 1000 flips
3) the percentage of heads flipped out of 1000 flips
4) the percentage of times neither Heads nor Tails were flipped out of 1000 flips
5) nothing at all
Answer: c. Explanation: The code iterates 1000 times, flipping the Coin and testing to see if this flip was a 0 (“Heads”) or 1 (“Tails”). The variable num counts the number of Heads and the variable value is then the percentage of Heads over 1000.