174k views
2 votes
Given the array we have made, write a method that prints the

contents of the array. Print everything in the array on its own
line.

User Bitsofinfo
by
8.1k points

1 Answer

3 votes

Final answer:

To print each element of an array on its own line, a loop is used within a method to iterate through the array elements and print them using System.out.println (for Java).

Step-by-step explanation:

To print the contents of an array on separate lines in a method, you will typically use a loop to iterate through each element of the array and print it. Here is an example assuming you are using a programming language like Java:

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

This method is called printArrayContents and it takes an array of integers as its parameter. When called, it will loop through the array and use System.out.println to print each element on a new line.

User Noorus Khan
by
7.9k points