// COMP 1631 (Fall 2006) // Author(s): 1631 instructors // // Lab Test code - Wednesday solution // // This class is just a holder for the main method which contains two loops // and a blank space where students are required to insert code (which will // involve another loop). public class LoopyWednesday { public static void main(String[] args) { final int defaultSize = 50; // default size of array int n; // user-specified size of array int[] data; // uninitialized array int index; // index into array // get size of array and "build" it n = Console.readInt("Please enter a positive integer: "); if (n <= 0) { n = defaultSize; } // if data = new int[n]; // fill array with values 0, 1, 2, 3, ... index = 0; while (index < n) { data[index] = index; index++; } // while //------------------------------------------------------------------------ // fill the array with the sequence 0, -1, -4, -9, -16, -25, ... index = 0; while (index < n) { data[index] = - data[index] * data[index]; index++; } // while //------------------------------------------------------------------------ // print out the array System.out.println(); // blank line System.out.println("Here are the values in the array:"); index = 0; while (index < n) { System.out.println(" data[" + index + "] = " + data[index]); index++; } // while } // main method } // end class LoopyWednesday