-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP24_NumberDiamondPattern.java
More file actions
39 lines (32 loc) · 1.09 KB
/
Copy pathP24_NumberDiamondPattern.java
File metadata and controls
39 lines (32 loc) · 1.09 KB
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
package programs;
/**
* ============================================================
* PROGRAM 24: Palindromic Number Pyramid Pattern
* ============================================================
* Problem: WAP to print a palindromic number pyramid pattern.
*
* Example (n = 5):
* 1
* 2 1 2
* 3 2 1 2 3
* 4 3 2 1 2 3 4
* 5 4 3 2 1 2 3 4 5
* ============================================================
*/
public class P24_NumberDiamondPattern {
public static void printPalindromicPyramid(int n) {
System.out.println("=== PALINDROMIC NUMBER PYRAMID (n=" + n + ") ===");
for (int r = 1; r <= n; r++) {
// Spaces
for (int s = 1; s <= (n - r); s++) System.out.print(" ");
// Descending numbers: r down to 1
for (int d = r; d >= 1; d--) System.out.print(d + " ");
// Ascending numbers: 2 up to r
for (int a = 2; a <= r; a++) System.out.print(a + " ");
System.out.println();
}
}
public static void main(String[] args) {
printPalindromicPyramid(5);
}
}