Question: Assuming line 3 generates a random number between [ 1 - 5 0 0 ] , which one of the following is true about the

Assuming line 3 generates a random number between [1-500], which one of the following is true about the following code:
1. ArrayList lst = new ArrayList();
2. for (int i =0; i <400; ++i){
3. int rnd =1+(int)(Math.random()*500);
4. if (!lst.contains(rnd)){
5. lst.add(rnd);
6.}
7.}
Group of answer choices
It adds the numbers [0-399] to the list
It only adds values to the list that are not already in the list
Compile error because contains method returns an int value
It only adds duplicate values to the list

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 Programming Questions!