Java
TOPIC 18 – TEST II REVIEW
SOLUTIONS TO QUESTION 4
a) 60%
There is a 40% chance that "A" is outputted. Otherwise, "B" will be outputted
so that's a 60% chance.
b) 30%
There is a 20% chance of "A" being outputted. That leaves with a 30% chance of outputting
"B".
c) 30%
There are two statement blocks where "B" gets outputted. The first block has a 10% of getting
executed. The last block has a 20%
chance. So in total, there is a 30%
chance.
d) 20%
There is a 50% chance that we enter the first IF statement block. Then, once there, there is a 60% chance we
output "A" (notice that there is a > symbol). So that means there is a 40% chance that we
output "B".
So, combining the 50% and the 40% by multiplying them, we get 20% overall.
|