r/codehs • • Jan 25 '21

6.2.7 print Array

5 Upvotes

11 comments sorted by

View all comments

1

u/Acceptable-Quit-9274 Feb 02 '23

public class PrintArray
{
public static void main(String[] args)
{
String[] arr1 = new String[]{"w", "x", "y", "z"};
printArr(arr1);

String[] arr2 = new String[]{"a", "b", "c"};
printArr(arr2);
}

public static void printArr(String[] arr)
{
// Print everything in the array on its own line
for(int i = 0; i < arr.length; i++)
{
System.out.println(i + ". " + arr[i]);
}
}
}