Answer:
if ( array.length != 0 ) { . . . System.out.println("The average is: " + total / array.length ); } else System.out.println("The array contains no elements." );
End of the Chapter
That about wraps it up for this chapter. You may wish to review the following topics, unless you are already maxed out. Click on a subject that interests you to go to where it was discussed.
- Counting loops and arrays.
-
The
lengthattribute of an array. - Array length determined at run time.
- Enhanced for loops
- Algorithm for determining the maximum element.
- Algorithm for determining the minimum element.
- Algorithm for determining the sum of the elements in an array.
- Algorithm for determining the average of the elements in an array.