Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have three identical prizes to give away and a pool of 30 finalist. The fina

ID: 3621616 • Letter: Y

Question

You have three identical prizes to give away and a pool of 30 finalist. The finalists are assigned numbers from 1 to 30. write a program to randomly select the numbers of three finalists to receive a price. Make sure not to pick the same number twice. for example, picking finalist 3, 15, 29 would be valid but picking 3,3,31 would be invalid because finalist 3 is listed twice and 31 is not a valid finalist number. the following line of code can be used to generate a random number between 1 and 30

int num = (int) (math.random() * 30) +1;

Explanation / Answer

please rate - thanks

public class main
{public static void main(String []args)
{int []list= new int[3];
int j,n,count=1;
boolean used=true;
n=(int) (Math.random() * 30) +1;
list[0]=n;
for(count=1;count<3;count++)
{do
    {used=false;
     n=(int) (Math.random() * 30) +1;
    for(j=0;j<count;j++)
        if(n==list[j])
            used=true;
        }while(used);
    list[count]=n;       
    }
System.out.print("The finalists are: ");
for(j=0;j<3;j++)
    System.out.print(list[j]+" ");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote