Consider the incomplete method ChoiceOfThree. public int choiceOfThree() { // mi
ID: 3643442 • Letter: C
Question
Consider the incomplete method ChoiceOfThree.public int choiceOfThree()
{
// missing code
}
Method choiceOfThree is intended to return one of the values 1, 2, 3, each with probability 1/3. Consider the following replacements for //missing code.
I. return (int)(Math.random() * 3);
II. return (int)(Math.random() * 3) + 1;
III. if(Math.random() < 1.0/3.0)
return 1;
else if (Math.random() < 2.0/3.0)
return 2;
else
return 3;
Which if these replacements for //missing code will make choiceOfThree work as intended?
Explanation / Answer
I and III