Question: 1)I need to explain this: Copy the code in the GivenCode1.txt file and run it on a Java program . You will get an output.

1)I need to explain this:

Copy the code in the GivenCode1.txt file and run it on a Java program . You will get an output. Explain the reasons to get this output in a text file.

1)I need to explain this: Copy the code in the GivenCode1.txt file

Please just write the reason why that certain output is given.

Here is the CodeGiven1.txt File:

/* This program will show the difference between

1. Using the assignment operator (=) to copy two arrays

2. Using the Arrays.copyOf method to copy the two arrays

*/

import java.util.Arrays;

public class GivenCode1

{

public static void UseAssignmentOperator()

{

int[] originalArray = {1,2,3,4,5};

int[] copiedArray = originalArray;

for(int i=0; i

{

copiedArray[i] = copiedArray[i]*2;

}

// Print the copiedArray

System.out.println("Use Assignment Operator");

System.out.println("Copied Array");

for(int i=0; i

{

System.out.print(copiedArray[i] + " ");

}

System.out.println(" Original Array");

for(int i=0; i

{

System.out.print(originalArray[i] + " ");

}

}

public static void UseCopyOfMethod()

{

int[] originalArray = {1,2,3,4,5};

int[] copiedArray =

Arrays.copyOf(originalArray,originalArray.length);

for(int i=0; i

{

copiedArray[i] = copiedArray[i]*2;

}

// Print the copiedArray

System.out.println(" Use Copy Of Method");

System.out.println("Copied Array");

for(int i=0; i

{

System.out.print(copiedArray[i] + " ");

}

System.out.println(" Original Array");

for(int i=0; i

{

System.out.print(originalArray[i] + " ");

}

}

public static void main(String[] args)

{

UseAssignmentOperator();

UseCopyOfMethod();

}

}

2)I need to explain this too:

"Copy the code in the GivenCode2.txt file and run it on a Java program . You will get an output. Explain the reasons to get this output in a text file."

and run it on a Java program . You will get an

Please just write the reason why that certain output is given.

Here is the GivenCode2 File:

public class GivenCode2 {

public static void changeArray(int[] x)

{

for(int i=0; i

{

x[i] = x[i]*2;

}

}

public static void main(String[] args)

{

int[] arr = {1,2,3,4,5};

System.out.println("Array arr in the main method - Before calling to the method changeArray ");

for(int i=0; i

{

System.out.print(arr[i] + " ");

}

//Call to the method changeArray by passing the array arr

changeArray(arr);

System.out.println(" Array arr in the main method -After calling to the method changeArray ");

for(int i=0; i

{

System.out.print(arr[i] + " ");

}

}

}

Actual Java Program needed:

Declare a String array list called classList1 and do the followings:

a. Add the following students to the list. Andrew, Lesley, Taylor, Heather , Lily

b. Display names using the print statement.

c. Display names in separate lines using a loop.

d. Replace the name at index 3 to Heather. Display names in classList1 using the print statement.

e. Insert name Cathy between Andrew and Lily. Display names in classList1 using the print statement.

f. Remove the name Taylor from the list. Display names in classList1 using the print statement.

.

Use Assignment Operator Copied Array 2 4 6 8 10 Original Arrav 2 4 68 10 Use Copy of Method Copied Array 2 4 6 8 10 O av riginal Arr 1 2 3 4 5

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!