/* * One class with static methods. * An array of random numbers from 1 to 10 inclusive. * This array is declared empty, without literal values. * NOTE: A arbitary range of random numbers ie 13 to 27 is not covered here. */ package arrayrandomscanner3; public class ArrayNameScanner3 { // global private static variables for all methods in the class // This is the second way to declare an array // The array has 6 spaces but does not have any values private static int[] RandomArray = new int[6]; public static void main(String[] args) { GenerateRandom(); } private static void GenerateRandom() { // "length" always goes to the end of the array // Generates random numbers from 1 to 10 System.out.println("Six random numbers stored in an array."); for(int i = 0; i < RandomArray.length; i++ ){ // We add one to avoid getting 0 to 9. int randomNumber = (int)(Math.random() * 10) + 1; RandomArray[i] = randomNumber; System.out.println(RandomArray[i]); } } } // ============================================================================= OUTPUT Six random numbers stored in an array. 8 1 10 9 7 8