Array Element Shifting With A For Loop
Consider the following code segment.
int[] arr = {1, 2, 3, 4, 5, 6, 7};
for (int k = 3; k < arr.length - 1; k++) {
arr[k] = arr[k + 1];
}
Which of the following represents the contents of arr after the code segment has been executed?
A
{1, 2, 3, 5, 6, 7, 8}
B
{1, 2, 3, 5, 6, 7, 7}
C
{1, 2, 3, 4, 5, 6, 7}
D
{2, 3, 4, 5, 6, 7, 7}
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | vempaami000 | 1 | 1 | 0m 00s | 100 |
| #2 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #3 | zgj07310417 | 1 | 1 | 0m 41s | 59 |
| #4 | singh.advik13 | 1 | 2 | 1m 02s | 28 |
| #5 | singhris000 | 1 | 1 | 1m 40s | 0 |
| #6 | gizemsever68+tester | 0 | 1 | 0m 00s | -10 |
| #7 | psak12 | 1 | 1 | 3m 46s | -126 |
| #8 | bommasam000 | 0 | 3 | 1m 46s | -136 |
| #9 | y.seong2027 | 1 | 2 | 5m 25s | -235 |
| #10 | geethasailaja | 1 | 2 | 18m 36s | -1,026 |
Items per page:
10
1 – 10 of 10
APFIVE