I am trying to use 2D array to print an image, but it is wrong. How can I fix this?
int n = 4;
int m = 6;
String num[][] = new String[n][m];
System.out.println("Bài 1c : ");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i == 0 || (i % 2 != 0 && j % 2 != 0)
|| (i % 2 == 0 && j % 2 == 0) || i != n - 1) {
System.out.print(num[i][j] = "A");
} else {
System.out.print("B");
}
}
System.out.println();
}
The output should be:
AAAAAA
BABABA
ABABAB
BBBBBB
Any help would be great!