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.
You might also like to view...
The Declare statement allocates __________ storage locations to the array named Photos[23].
Fill in the blank(s) with correct word
Specifying _________ as a parameter to Peedy’s Play method causes him to smile.
a) "Think" b) "Smile" c) "Pleased" d) "Happy"
Match the following items related to the background to their descriptions:
I. Tile A. Displays a single image at its actual size, in the middle of the desktop. II. Center B. Displays a single image, resized to fill the desktop. III. Stretch C. Displays multiple thumbnail-sized copies of the same image in columns and rows across the desktop. IV. Windows Classic D. The default background for Windows XP. V. Bliss E. Displays windows that have trim, straight-edged bars, borders, and buttons.
A(n) ________ is the number that displays at the left of a row
Fill in the blank(s) with the appropriate word(s).