219k views
23 votes
Please help w/ Java, ASAP!!!!

Please help w/ Java, ASAP!!!!-example-1
Please help w/ Java, ASAP!!!!-example-1
Please help w/ Java, ASAP!!!!-example-2
User GeorgeU
by
5.0k points

1 Answer

3 votes

Answer:

B

Step-by-step explanation:

When you have a method that is copying values from one array into another, you first have to initialize a new array which you can copy the values into. This is done by using the provided value "count".

int [ ] nums = new int [count];

Second, you have a "for each" loop that iterates over each index in the first array, and assigns the value at that index to the same index location in the copy array. In a "for each" loop, the variable "val" represents the content of an index, not an iterated value itself. This is why we can just do this inside the loop:

nums[ j ] = val;

That said, you still need "j" to be there and increment because we still need a tracking value for the current index in the copy array.

int j = 0;

for (int val: array)

{

copyArray[j] = val;

j++;

}

Third, you return the copy version of the array.

return nums;

Source:

I am currently a second year Java student.