Here are the directions:
Implement the following method so that it prints all even-valued elements from the even-indexed rows of arr, and all odd-valued elements from the odd-indexed rows of arr.
Elements of the same row should appear on the same line, separated by a space. Elements of different rows should appear on different lines.
Example:
int[][] arr = {{1, 2, 3},
{1, 2, 3}
{4, 5, 6}};
printOddEvens(arr);
Should print:
2
1 3
4 6
This is what I have, way off, but in the right direction:
(I know the prints are wrong.)
public static void main(String[] args) {
int arr[][] = {{1,2,3},{1,2,3},{4,5,6}};
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (i % 2 == 0) {
System.out.println(arr[i][j]);
}
if (!i % 2 == 0) {
System.out.println(arr[i][j]);
}
}
}
}
Here is the solution:
One less future competitor for my job I guess (-;