int sum = 0;
for (int i = 0; i < a.length; i++) {
sum += a[0];
}What is the bug?
- A
sum should be initialized to 1
- B
Loop should run a.length+1 times
- C
Nothing is wrong
- Dcheck_circle
a[0] should be a[i] to sum every element
Explanation
Always indexing a[0] adds the first element repeatedly. Use a[i] to access the current element.