1. Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as:

    All that and more! Registration is quick, simple and absolutely free. Join our community today!

Generate a pyramid

Discussion in 'Coding, Programming' started by Bhadz141, Sep 23, 2016.

  1. public class Pyramid
    {
    /* Generate a Pyramid using * symbols */
    public static void main(String[] args)
    {
    int n = 8; // number of rows

    int indent = 3;
    for (int i = 1; i <= n; i++)
    {
    for (int j = 0; j < ((n + indent) - i); j++)
    System.out.print(" ");
    for (int k = 1; k <= i; k++)
    System.out.print("*");
    for (int k = 1; k < i; k++)
    System.out.print("*");
    System.out.println();
    }

    System.out.println();
    }
    }
     
  2. Path_Finder

    Path_Finder Grasshopper Established

Tags / Keywords: