To emphasize the underscore to the left of the pyramid, simply change the value when you exit the dash. Make sure you are still creating a new line after each loop.
Dash example on the left:
public static void main(String[] args)
{
for(int height=0; height<5; height+=2)
{
System.out.print("-");
for(int width=5; width-height>0; width--)
{
System.out.print("*");
}
System.out.println();
}
}
Here is a method that will turn the pyramid upside down. I changed some of your loops for this, but it is pretty straight forward. Just change the value of the pyramidHeight variable to change the height of the pyramid's output.
An example of an inverted pyramid:
public static void main(String[] args) {
int pyramidHeight = 3;
for(int height=0; height<pyramidHeight; height++)
{
for(int width=height+1; width>0; width--)
{
System.out.print("-");
}
for(int width = 1 + (((pyramidHeight-1) - height) * 2); width>0; width--)
{
System.out.print("*");
}
System.out.println();
}
}
source
share