I'm trying to do a two dimensional for loop that with print this:
7 5 3 1
2 4 6 8
Here is my array:
int [][] secondArray = {{7, 5, 3, 1}, {2, 4, 6, 8}};
The for loop below will only print it one number after the other. Not all on one straight line. I have tried playing around with it. Like making two print statements. On for i and j. Or doing a "\t". I'm just learning arrays and this for loop was the closest example I got online.
for(int i = 0; i < secondArray.length ; i++)
{
for(int j = 0; j < secondArray[i].length; j++)
{
System.out.println(secondArray[i][j]);
}
}
Edit: I guess I should put that I understand how for loops work. It goes through each number and prints it. I guess my question is, how else would I do this?
The for loop below will only print it one number after the other. Not all on one straight linethen it should beSystem.out.print(secondArray[i][j] + " ");