Palindromic number pyramid pattern in java.

■》Code link -> click πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡

 

https://www.programiz.com/online-compiler/65x6aqyJmV33X


■ Program->

import java.util.*;

public class palindromepyramid {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        System.out.println("enter the no. of rows=");

        int n=sc.nextInt();

        for(int i=1; i<=n; i++){

            for(int j=1; j<=n-i; j++){

                System.out.print(" ");

            }

            // for 1st part

            for(int j=i; j>=1; j--){

                System.out.print(j);

            }

            // for 2nd part

            for(int j=2; j<=i; j++){

                System.out.print(j);

            }

            System.out.println();

        }

    }

}

■》Output->

enter the no. of rows=5

       1

     212

   32123

  4321234

543212345



Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.