Skip to content

Commit 3827bd1

Browse files
authored
Create pat.java
1 parent 08797af commit 3827bd1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pat.java

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Java Program to print pattern
2+
// Palindrome 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+
11+
// outer loop to handle number of rows
12+
for (i = 1; i <= n; i++) {
13+
// inner loop to print the spaces
14+
for (j = 1; j <= 2 * (n - i); j++) {
15+
System.out.print(" ");
16+
}
17+
18+
// inner loop to print the first part
19+
for (j = i; j >= 1; j--) {
20+
System.out.print(j + " ");
21+
}
22+
23+
// inner loop to print the second part
24+
for (j = 2; j <= i; j++) {
25+
System.out.print(j + " ");
26+
}
27+
28+
// printing new line for each row
29+
System.out.println();
30+
}
31+
}
32+
33+
// Driver Function
34+
public static void main(String args[])
35+
{
36+
int n = 6;
37+
printPattern(n);
38+
}
39+
}

0 commit comments

Comments
 (0)