We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents c3ba10f + d33a808 commit 81c8ef2Copy full SHA for 81c8ef2
triangle.java
@@ -0,0 +1,35 @@
1
+// Java Program to print pattern
2
+// Zero-One triangle
3
+import java.util.*;
4
+
5
+public class GeeksForGeeks {
6
+ // Function to demonstrate pattern
7
+ public static void printPattern(int n)
8
+ {
9
+ int i, j;
10
+ //outer loop to handle number of rows
11
+ for (i = 1; i <= n; i++) {
12
+ //inner loop to handle number of columns
13
+ for (j = 1; j <= i; j++) {
14
+ // if the sum of (i+j) is even then print 1
15
+ if ((i + j) % 2 == 0) {
16
+ System.out.print(1 + " ");
17
+ }
18
+ // otherwise print 0
19
+ else {
20
+ System.out.print(0 + " ");
21
22
23
24
+ //printing new line for each row
25
+ System.out.println();
26
27
28
29
+ // Driver Function
30
+ public static void main(String args[])
31
32
+ int n = 6;
33
+ printPattern(n);
34
35
+}
0 commit comments