Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i know there may be better ways of doing this but this is directly out of teache

ID: 3569777 • Letter: I

Question

i know there may be better ways of doing this but this is directly out of teachers powerpoint slide so i need to use this....its java code... its a method to copy and return array. The code is below im just curious how i would properly call that within my main so it would print the copy when i run the program. As it stands now i called it like this System.out.print(copyArr(grades)); // i named my array grades but when i run the program it only prints the reference address. it doesnt actually print the copy.

static int[][] copyArr(int[][] array){

    //create a local 2-d array

    int[][] copy = new int[array.length][array[0].length];

    //copy each element of the array

    for (int i = 0; i < array.length; i++)

       for (int j = 0; j < array[i].length; j++)

          copy[i][j] = array[i][j];

    return copy; //return the array created

}

Explanation / Answer

See you made a slight mistake in the calling section.

The method is returning an entire 2-d array so you just can't print out that array using a single print statement. What you need to do is that you need to create another 2-d array of the same size in your calling section(main or whatever) and you need to store the result returned from this function in that array. Once you have done that,print the entire array contents using for loops.

Hope this answer helps!