How to print in Pyramid of Numbers in Java?

0 Comments

Below programs display the pyramid of numbers based on user input

// Library to import

import java.util.Scanner;

Scanner input = new Scanner (System.in); // for taking input from user

System.out.println("Enter the Input Number that how many times do you want to get pyramid of numbers : ");

int inputNumber = input.nextInt();// take input from user

for (int row = 1  ; row <= inputNumber; row++){

for (int space = inputNumber-1; space>=row; space--)

System.out.print(" ");

for (int left = row; left <= row+(row-1); left++)

System.out.print(left);

for(int right = (row-3)+(row+1); right >= row; right--)

System.out.print(right);

System.out.println();


Leave a Reply

Your email address will not be published.