Equilateral Triangle Of Order N*N In Java
class pattern1{
public static void main(String[] args) {
int str = 5, spc = 0, 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<=str; j++ ) //loop to print star in the loop.
{
System.out.print("* ");
}
System.out.println();
str--;
spc++;
}
}
}
Output:
No comments:
Post a Comment