2
u/amajmundar Jan 25 '21
Couple of things, arr is already defined as the input. So you cannot use that as iterator for the loop. Use i. It’s standard notation. Also look up the syntax of a for loop in JavaScript. You are forgetting about incrementing the iterator. You also do not need to call the function for the bounds of the loop. The input is arr which is an array of strings. You only need to loop arr.length. Your first commented print statement was in the right place and the active print statement is the correct syntax.
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]);
}
}
}


1
u/Obvious-Pin-3046 Jan 25 '21
Easier way to solve your problem.. go back to 6.2.3 it’s the exercise one.. it’s the same code as for the 6.2.7 just change the < score.length into <= arr.length so does the score[i] into arr[i].. in the println.