/** * Demonstrates array concepts in W10N01 * * @author Pete Nordquist * @version 061128 */ public class W10N01 { private String[] a; public W10N01(int arrLen) { // if the user passes in a reasonable number if (arrLen > 0) // create an array of the length the user wants a = new String[arrLen]; else // make the array contain 10 elements a = new String[10]; // foreach element in the array s for (int i = 0; i < a.length; i++) // set the corresponding element in array a to // a string representation of the integer that is its index a[i] = "" + i; } public void printElements() { for (int i = 0; i < a.length; //size of the array i++) { System.out.println(a[i]); } // for loop counter initialization statement int i = 0; // keep for loop conditional expression while (i < a.length) { System.out.println(a[i]); i++; } } }