Common Array Algorithms

This chapter discusses how a for loop can be used to iterate over the elements of a one-dimensional array. In addition, it also discusses enhanced for loops. The chapter demonstrates the use of arrays to solve common problems such as finding sum, average, maximum, and minimum values of numbers stored in array. Pay attention to some of the common programming errors one can make while using arrays.

1. Common Array Algorithms

lineOfBoxesAn array that uses a single subscript is called a one dimensional array. This is because one index is used to access the values in the array. Its cells are like numbered boxes lined up one after the other in a line.

A two dimensional array requires two indexes to access values. Its cells are like boxes arranged into a rectangle. Arrays of even higher dimension are possible, although rarely used. This chapter discusses typical ways to use one dimensional arrays.


Chapter Topics:

      • Arrays and counting loops
      • Enhanced for loop
      • The length of an array
      • Finding the maximum and minimum of an array of numbers
      • Finding the sum of the elements of an array
      • Computing the average of the elements of an array

Question 1:

How could you print out every element of an array with 100 cells?


Source: Bradley Kjell, http://programmedlessons.org/Java9/chap61/ch61_01.html
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 License.