</> ᴍᴜᴋᴇsʜ </>
0-1 Triangle Pattern
public class zeroone {
public static void zeroOne_Triangle(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if ((i + j) % 2 == 0) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
}
System.out.println();
}
}
public static void main(String[] args) {
zeroOne_Triangle(5);
}
}
Output:
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
2 · 1.2K ·