Arrays

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

Lotto.java
// Ask user for MAX_SELECT numbers out of [1..MAX_NUMBERS]
int[] selectedNumbers = new int[MAX_SELECT]; // by the user
for (int index = 0; index < MAX_SELECT; ++index) {
   int selected = RitIo.getInteger("Number " + (index + 1)
                                   + ": ");
   selectedNumbers[index] = selected;
}

*Arrays are objects that contain a number of variables that are all of the same type.
 
*The variables of an array are called components.
 
*The number of components in an array is called its length.
 
*Like objects, arrays are dynamically created using the new operator and at that time the length must be decided upon.
 
*The components of an array have no individual names but are addressed by index numbers from 0 to n - 1 if n is the length of the array.
 
*Declaration Syntax: Component Type []
 
*Expression Syntax: Expression [ IndexExpression ]
 
*Indices must be of type int, short, byte, or char.
 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002