5.15. Review Questions

 
[Page 169]

Chapter 6. Arrays

Mayan God Shel, Mexico. Photographer: Philip Coblentz. Courtesy Brand X Pictures.

Objectives

  • To describe why arrays are necessary in programming ( §6.1).

  • To learn the steps involved in using arrays: declaring array reference variables and creating arrays ( § §6.2.1 “6.2.2).

  • To initialize the values in an array ( §6.2.3).

  • To access array elements using indexed variables ( §6.2.4).

  • To simplify programming using the JDK 1.5 foreach loops ( §6.2.5).

  • To declare, create, and initialize an array using an array initializer ( §6.2.6).

  • To copy contents from one array to another ( §6.3).

  • To develop and invoke methods with array arguments and return values ( § §6.4 “6.5).

  • (Optional) To declare a method with variable-length argument list ( §6.6).

  • To search elements using the linear ( §6.7.1) or binary ( §6.7.2) search algorithm.

  • To sort an array using the selection sort ( §6.8.1).

  • (Optional) To sort an array using the insertion sort algorithms ( §6.8.2).

  • To use the methods in the Arrays class ( §6.9).

  • To declare and create two-dimensional arrays ( §6.10).

  • (Optional) To declare and create multidimensional arrays ( §6.11).


[Page 170]

6.1. Introduction

Often you will have to store a large number of values during the execution of a program. Suppose, for instance, that you want to read one hundred numbers, compute their average, and find out how many numbers are above the average. Your program first reads the numbers and computes their average, and then compares each number with the average to determine whether it is above the average. The numbers must all be stored in variables in order to accomplish this task. You have to declare one hundred variables and repeatedly write almost identical code one hundred times. From the standpoint of practicality, it is impossible to write a program this way. An efficient, organized approach is needed. Java and all other high-level languages provide a data structure, the array , which stores a fixed- size sequential collection of elements of the same type.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net