/* In Class problem: Write a program to set up an array of 8 values. Randomly generate 8 numbers from 1-10 to store in the array. Then print them out in the reverse order in which they were generated.*/ public class InClassExercise { public static void main(String[] args) { // This example stores the values and prints them at the same time // moving backwards through the array. int z[]; z = new int[8]; for (int x = 7; x >= 0; x --) { z[x] = 1+(int)(Math.random()*10); System.out.println("z[ "+x+"] is "+z[x]); } // This example stores the values the values while moving forward // through the array and then prints them in the reverse order in which // they were generated. int x[]; x = new int[8]; int i; // Generate a random number from 1-10 System.out.println("\nHere is the second example:"); for (i=0; i<8; i++) { x[i] = 1 + (int) (Math.random() * 10); System.out.println("The element " + i+ " is " + x[i]); } System.out.println("\nNow the numbers are printed in reverse order:"); for (i=7; i>=0; i--) System.out.println("The element " + i+ " is " +x[i]); System.out.print("\n"); System.exit(0); } // end of main } // end of class