The following code uses a for loop to sum the elements of an array. Find the error(s) in the following code:

```
1 public void sumArray()
2 {
3 int[] numbers = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
4
5 for ( int counter = 0; counter <= numbers.size; counter++ )
6 {
7 int sum += numbers[ counter ];
8 }
9 } // end method sumArray
```

The expression numbers.size should be numbers.length. Variable sum should be declared outside of the loop.

Computer Science & Information Technology

You might also like to view...

If gridlines do not show on a table without borders, click the Borders button arrow on the ________ tab, and then click View Gridlines

A) Table Tools Layout B) View C) Table Tools Design D) Page Layout

Computer Science & Information Technology

The user can utilize the horizontal scroll bar to move up and down to view information that extends beyond the top or bottom of the screen

Indicate whether the statement is true or false

Computer Science & Information Technology