Question: Consider the following array: int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 }; What are the contents of the
Consider the following array:
| int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 }; |
What are the contents of the array a after the following loops complete?
| 1 2 3 4 5 | int i = 1; while (i < 10) { a[i] = a[i - 1]; i++; } |
| 1 2 3 4 5 | int i = 9; while (i > 0) { a[i] = a[i - 1]; i--; } |
| 1 2 3 4 5 | int i = 0; while (i < 9) { a[i] = a[i + 1]; i++; } |
| 1 2 3 4 5 | int i = 8; while (i >= 0) { a[i] = a[i + 1]; i--; } |
| 1 2 3 4 5 | int i = 1; while (i < 10) { a[i] = a[i] + a[i - 1]; i++; } |
| 1 2 3 4 5 | int i = 1; while (i < 10) { a[i] = 0; i = i + 2; } |
| 1 2 3 4 5 | int i = 0; while (i < 5) { a[i + 5] = a[i]; i++; } |
| 1 2 3 4 5 | int i = 1; while (i < 5) { a[i] = a[9 - i]; i++; } |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
