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.
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." 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. .
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started