Hi Guys, I'm trying to have the user enter an integer than an outline of a pyramid would be printed on the console.
I just can't get the last line to print out with "*" all across.
So say a user enters 5 I need the output to be:
*
* *
* *
* *
*********
Any hints or tips would be greatly appreciated
import java.util.Scanner;
public class Pyramid {
public static void main(String[] args) {
int width;
System.out.print("How many rows :");
Scanner kb = new Scanner(System.in);
width = kb.nextInt();
for (int i = 1; i <= width; i++) {
for (int j = 1; j <= width - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * width - 1; j++) {
if (j == i || j==1) {
System.out.print("*" + " ");
}else {
System.out.print(" " + " ");
}
}
System.out.println();
}
}
}