Question: Consider the following array: int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 }; What is the value of total
Consider the following array:
int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 };
What is the value of total after the following loops complete?
a. int total = 0;
for (int i = 0; i < 10; i++) { total = total + a[i]; }
b. int total = 0;
for (int i = 0; i < 10; i = i + 2) { total = total + a[i]; }
c. int total = 0;
for (int i = 1; i < 10; i = i + 2) { total = total + a[i]; }
d. int total = 0;
for (int i = 2; i <= 10; i++) { total = total + a[i]; }
e. int total = 0;
for (int i = 1; i < 10; i = 2 * i) { total = total + a[i]; }
f. int total = 0;
for (int i = 9; i >= 0; i--) { total = total + a[i]; }
g. int total = 0;
for (int i = 9; i >= 0; i = i - 2) { total = total + a[i]; }
Step by Step Solution
3.48 Rating (165 Votes )
There are 3 Steps involved in it
a for int ... View full answer
Get step-by-step solutions from verified subject matter experts
