Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Data Collections
Start Practice TestPractice Test
About Exam
medium Solved by 3 students

Array Population with Random Integers

Mark
< Prev
Next >

Consider the following code segment, which is intended to populate an array with random integers from 0 to 100, inclusive.

int listLength = 10;
int[] list = new int[listLength];
for (int i = 0; i < listLength; i++) {
  /* code to add integer to list */
}
return list;

Which statement, if it replaces /* code to add integer to list */, will cause the segment to work as intended?

A

list[i] = (int) (Math.random() * 100);

B

list[i] = (int) (Math.random() * 101);

C

list.add((int) (Math.random() * 101));

D

list[i] = (int) (Math.random() * 100) + 1;

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1nabihamanahal22 - 200
#2lsj0803092211 1m 38s 2
#3hridaansingal.17401 - -10
#4ravi.palepu01 - -10
#5michael.matveyev12 1m 49s -19
Items per page:
10
1 – 5 of 5
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|