Try this:
public static void main(String[] args) {
for(int i=0;i<5;i++) {
for(int j=0;j<5-i;j++) {
System.out.print(" ");
}
for(int k=0;k<=i;k++) {
System.out.print("* ");
}
System.out.println();
}
}
Output:
*
* *
* * *
* * * *
* * * * *
Just for your knowledge System.out.println
will print on a new line where System.out.print
will print in the same line.
0
solved Print pyramid pattern in java [duplicate]