Array Population with Random Integers
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;
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | nabihamanahal | 2 | 2 | - | 200 |
| #2 | lsj08030922 | 1 | 1 | 1m 38s | 2 |
| #3 | hridaansingal.174 | 0 | 1 | - | -10 |
| #4 | ravi.palepu | 0 | 1 | - | -10 |
| #5 | michael.matveyev | 1 | 2 | 1m 49s | -19 |
Items per page:
10
1 – 5 of 5
