Skip to content

Commit 81c8ef2

Browse files
Merge pull request #220 from Udit1542/patch-2
Hacktoberfest2023
2 parents c3ba10f + d33a808 commit 81c8ef2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

triangle.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)