Think of your pyramid as drawn on a coordinate system. You need to make sure that both the x-coordinate and the y-coordinate move in the whole program.
Scanner pal = new Scanner (System.in);
System.out.println("Enter the number of rows you want");
int n = pal.nextInt();
int rows = 0;
while (rows < n)
{
int column = 0;
while (column < n - rows)
{
System.out.print(" ");
column++;
}
int currentStars = 0;
while (currentStars <= rows)
{
System.out.print(" *");
currentStars++;
}
System.out.print("\n");
rows++;
}
This should get your program running. However, take time to understand why this works.
0
solved Pyramid of asterisk using while loop in java