// ----------------------------------------------------------------------------- // ArrayApp.java // ----------------------------------------------------------------------------- /** * ----------------------------------------------------------------------------- * Used to provide an example of using Java arrays as a simple data structure. * @author Jeffrey Hunter * ----------------------------------------------------------------------------- */ public class ArrayApp { long[] arrayElems; // Reference to array. int numElements; // Number of items to store in array object. public ArrayApp() { this(10); } public ArrayApp(int nElems) { // Instantiate new array object. arrayElems = new long[nElems]; numElements = 0; } public void loadArray() { // Insert several (10) items into array object arrayElems[0] = 77; arrayElems[1] = 99; arrayElems[2] = 44; arrayElems[3] = 55; arrayElems[4] = 22; arrayElems[5] = 88; arrayElems[6] = 11; arrayElems[7] = 00; arrayElems[8] = 66; arrayElems[9] = 33; // Indicate 10 items in array numElements = 10; } public void displayElements() { System.out.println(); System.out.println("DISPLAY ELEMENTS"); System.out.println("-----------------------------------"); System.out.println(" - Number of elements = " + numElements); System.out.print (" - "); for (int j=0; j