forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.java
39 lines (33 loc) · 797 Bytes
/
code.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Java Program to print pattern
// Palindrome triangle
import java.util.*;
public class GeeksForGeeks {
// Function to demonstrate pattern
public static void printPattern(int n)
{
int i, j;
// outer loop to handle number of rows
for (i = 1; i <= n; i++) {
// inner loop to print the spaces
for (j = 1; j <= 2 * (n - i); j++) {
System.out.print(" ");
}
// inner loop to print the first part
for (j = i; j >= 1; j--) {
System.out.print(j + " ");
}
// inner loop to print the second part
for (j = 2; j <= i; j++) {
System.out.print(j + " ");
}
// printing new line for each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 6;
printPattern(n);
}
}