Empty triangle pyramid program in Java.



package demo;
import java.util.Scanner;
public class BlankPyramid
{
 public static void main(String[] args) 
 {
  Scanner sc = new Scanner(System.in);
  int num;
  System.out.print("Enter no of rows: ");
  num = sc.nextInt();
  System.out.println("*");
  for (int r = 1; r <= num; r++) 
  {
   System.out.print("*");
   for (int sp = 1; sp < r; sp++) 
   {
    System.out.print(" ");
   }
   System.out.println("*");
  }
  for (int j = 1; j <= num + 2; j++) 
  {
   System.out.print("*");
  }
 }
}

Output:
Enter no of rows: 4

*
**
* *
*  *
*   *

******

BUILD SUCCESSFUL (total time: 3 seconds)


Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.

Thanks for visiting my Blog.