Palindromic Number Pyramid

This program prints a palindromic number pyramid.

Problem Statement

Write a Java program that prints a palindromic number pyramid with 5 rows.

Source Code

1 public class PalindromicPyramid {
2 public static void main(String[] args) {
3 int n = 5;
4 for(int i=1; i<=n; i++) {
5 for(int j=i; j<n; j++) System.out.print(" ");
6 for(int j=1; j<=i; j++) System.out.print(j);
7 for(int j=i-1; j>=1; j--) System.out.print(j);
8 System.out.println();
9 }
10 }
11 }

Program Output

    1    
   121   
  12321  
 1234321 
123454321

Explanation

Each row prints ascending numbers from 1 to the row index followed by descending numbers back to 1, forming a palindromic sequence per row and demonstrating symmetry in numeric patterns.

Quick Links to Explore