Question: Loops and Random What does the following method do ( assume the Random class has been imported ) : public static void question 5 (

Loops and Random
What does the following method do (assume the Random class has been imported):
public static void question5(){
int val=1;
int count =0;
boolean done = false;
Random r= new Random();
while (!done){
int num =r.nextInt (3)+2;
if (num -1==val ){
count++;
val = num;
} else {
count =0;
val=1;
}
done = count ==3;
}
}
sequence: 321 occurs.
chosen in a row.
Continues to iterate and pick random numbers (from the expression: until the
sequence: 210 occurs.
sequence: 012 occurs.
Continues to iterate and pick random numbers (from the expression: until the
sequence: 234 occurs.
sequence: 123 occurs.
 Loops and Random What does the following method do (assume the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!