import java.util.Scanner; public class eg01array { public static void main(String[] args) { final int EMPLOYEES = 3; int[] hours; //Unlike some languages, never put the size of the array in the declaration, it only creates array reference var hours = new int[EMPLOYEES]; // Allocate/create an array, assign address to hours varialbe //int[] hours = new int[EMPLOYEES]; // Declare and allocate. Scanner keyboard = new Scanner(System.in); System.out.println("Enter the hours worked by " + EMPLOYEES + " employees."); System.out.print ("Employee 1: "); hours[0] = keyboard.nextInt(); System.out.print ("Employee 2: "); hours[1] = keyboard.nextInt(); System.out.print ("Employee 3: "); hours[2] = keyboard.nextInt(); System.out.println("The hours you entered are: "); //System.out.println(hours[0]); //System.out.println(hours[1]); //System.out.println(hours[2]); for (int index = 0; index < EMPLOYEES; index++) { System.out.println(hours[index]); } int[] myhours = hours; //pointing to the same memory address (reference), two variables reference the same array for (int index = 0; index < EMPLOYEES; index++) { System.out.println(myhours[index]); } System.out.println ("Demo same memory address (by reference)"); hours[1] = 10; //changing one changes both due to reference System.out.println(myhours[1]); //note: java performs array bounds check at runtime, not compile time } }