I'm trying to create an 8x8 Alternating X and 0 that switches position in the next line
X0X0X0X0
0X0X0X0X
X0X0X0X0
0X0X0X0X
X0X0X0X0
0X0X0X0X
X0X0X0X0
0X0X0X0X
Instead my return is this
X
0
X
0
X
0
X
0
0
X
...
What is causing the code to always break line if I'm not using the \n statement
public class Main {
public static void main(String[] args) {
for (int row = 0; row < 8; row ) {
if (row % 2 == 0) {
for (int row1 = 0; row1 < 8; row1 ) {
if (row1 % 2 == 0) {
System.out.println("X");
} else {
System.out.println("0");
}
}
System.out.println("\n");
} else {
for (int row2 = 0; row2 < 8; row2 ) {
if (row2 % 2 == 0) {
System.out.println("0");
} else {
System.out.println("X");
}
}
System.out.println("\n");
}
}
}
}
CodePudding user response:
The ln
in println
stands for line.