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

Write two definitions of an overloaded method called print Array One method defi

ID: 3686313 • Letter: W

Question

Write two definitions of an overloaded method called print Array One method definition should accept a reference to a one - dimensional array of integers as a parameter and should print the elements of the array on a single line separated by space. The second method definition should accept a reference to a two - dimensional array of integers and two primitive integers called number Of Rows and number Of Columns as parameters and should print the element of the two - dimensional array as a table (optional: by calling the first method definition on each row of the two - dimensional array).

Explanation / Answer

public void printArray(int[] arr)
{
    for (int i = 0; i < arr.length; i++)
    {
        System.out.println(arr[i]);
    }
}

public void printArray(char[][] arr)
{
    for (int numOfRow = 0; row < arr.length; row++)
    {
        for (int numOfCol = 0; col < arr[row].length; col++)
        {
            System.out.print(arr[row][col] + " ");
        }
        System.out.println();
   }
}