Program To Print Pyramid Of Order N*N In Java Using Nested For Loop
int str = 1, spc = 5, i, j;
for ( i=1; i<=5; i++ ) // loop to represent rows in the pattern.
{
for ( j=1; j<=spc; j++ ) //loop to print space in the pattern.
{
System.out.print(" ");
}
for ( j=1; j<=2*str-1; j++ ) //loop to print star in the loop.
{
System.out.print("*");
}
System.out.println();
str++;
spc--;
}
}
}
Output:
No comments:
Post a Comment