Consider the following array: int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 }; What a
ID: 3666390 • Letter: C
Question
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++;
}
int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 };
Explanation / Answer
int i = 1;
while (i < 10) {
a[i] = a[i - 1];
i++;
}
int i = 9;
while (i > 0) {
a[i] = a[i - 1];
i--;
}
int i = 0;
while (i < 9) {
a[i] = a[i + 1];
i++;
}
int i = 8;
while (i >= 0) {
a[i] = a[i + 1];
i--;
}
int i = 1;
while (i < 10) {
a[i] = a[i] + a[i - 1];
i++;
}
int i = 1;
while (i < 10) {
a[i] = 0;
i = i + 2;
}
int i = 0;
while (i < 5) {
a[i + 5] = a[i];
i++;
}
int i = 1;
while (i < 5) {
a[i] = a[9 - i];
i++;
}
int i = 1;
while (i < 10) {
a[i] = a[i - 1];
i++;
}
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}int i = 9;
while (i > 0) {
a[i] = a[i - 1];
i--;
}
{ 1, 1, 2, 3, 4, 5, 4, 3, 2, 1}int i = 0;
while (i < 9) {
a[i] = a[i + 1];
i++;
}
{ 2, 3, 4, 5, 4, 3, 2, 1, 0, 0}int i = 8;
while (i >= 0) {
a[i] = a[i + 1];
i--;
}
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}int i = 1;
while (i < 10) {
a[i] = a[i] + a[i - 1];
i++;
}
{ 1, 3, 6, 10, 15, 19, 22, 24, 25, 25}int i = 1;
while (i < 10) {
a[i] = 0;
i = i + 2;
}
{ 1, 0, 3, 0, 5, 0, 3, 0, 1, 0}int i = 0;
while (i < 5) {
a[i + 5] = a[i];
i++;
}
{ 1, 2, 3, 4, 5, 1, 2, 3, 4, 5}int i = 1;
while (i < 5) {
a[i] = a[9 - i];
i++;
}
{ 1, 1, 2, 3, 4, 4, 3, 2, 1, 0}Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.