Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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."

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

Describe the four phases in the fraud investigation process.

Answered: 1 week ago

Question

Types of cultural maps ?

Answered: 1 week ago

Question

Discuss the various types of leasing.

Answered: 1 week ago

Question

Define the term "Leasing"

Answered: 1 week ago

Question

What do you mean by Dividend ?

Answered: 1 week ago