File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments