I have to write this in Java, but i've never even learned it before and i'm completely lost
Start a program in a class named ArrayPrinter. Ignore the main method for a moment.
In your class, create a static method named printArray with one parameter of type int[] named arr. Inside this method, do the following.

Keep all of your output in this method on one line using System.out.print() until directed to use println().
Display an opening square bracket character.
Loop through the array that was passed into the method. Display the values in the array. Add a comma and a space after every value except the last one.
Using System.out.println(), display a closing square bracket character.
In your main method, create the following array. Pass the reference to this array to the printArray method, run your program, and verify that it works as expected.

int[] oneD = {5, 6, 7, 8};
In your main method, add a blank println() statement after the method call you just made.
In the class, create an overloaded static method named printArray with one parameter of type int[][] named arr. Inside this method, do the following:
Using println(), display an opening square bracket character.
Loop through the two-dimensional array that was passed into the method.
First, use System.out.print() to display two space characters.
Every element of this two-dimensional array that you are looping through is a one-dimensional array of int. Call the other printArray method and pass to it each one-dimensional array in the two-dimensional array.
Using println(), display a closing square bracket character.
In your main method, create the following two-dimensional array. Pass the reference to this array to the printArray method, run your program, and verify that it works as expected.
int[][] twoD = {{2, 4, 6, 8},
{8, 7, 9, 1},
{3, 5, 1, 2}};
In your main method, add a blank println() statement after the method call you just made.
In your main method, create the following ragged two-dimensional array. Pass the reference to this array to the printArray method, run your program, and verify that it works as expected.

Respuesta :

Answer:

private void printArray(int[] arr){   //0

  System.out.print("[");   //1

  for(int k : arr){   //2

     System.out.print(k + ", ");   //3

  }

  System.out.println("]");   //4

}

Explanation:

This method should get you started. Your teacher may want a different format or a different type of loop. If you haven't learned for loops yet don't use them that'd be suspicious ;)

What I did:

0: This is the method heading with one parameter for the 1D array. If you need to access it in a different class change private to public.

1: This prints the [ with no line break

2: This is an enhanced for loop to iterate through each element in a 1D array. Alternatively, a normal for loop looks like this:

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

instead of retrieving the variable with the enhanced for, you'd have to use arr[i] instead of k in this scenario.

3: This prints the value in each pass of the loop along with a comma and a space.

4: This adds the ] with a line break when the loop is completed

Hope this helps you get started :D comment if you need further help