Question: public class copyArray { public static void main(String[] args) { int ARRAY_SIZE = 5; int[] array1 = {2, 4, 6, 8, 10}; int[] array2 =

public class copyArray

{ public static void main(String[] args)

{ int ARRAY_SIZE = 5; int[] array1 = {2, 4, 6, 8, 10}; int[] array2 = new int[ARRAY_SIZE];

//make array2 references a copy of array1 for(int index = 0; index < array1.length; index++) array2[index] = array1[index]; //change one of the elements using array1 array1[0] = 200;

//change of of the elements using array2 array2[4] = 1000;

//display all of the elements using array1

System.out.println("The contents of array1:");

for(int value : array1)

System.out.print(value + " ");

System.out.println();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!