Step-by-step explanation:
public class TrainglePattern{
public static void Triangle(int rows)
{
//i=rows-1 (this is to start with the maximum number of stars)
for (int i=rows-1; i>=0; i--)
{
for (int j=rows-i; j>1; j--)
{
System.out.print(" ");
}
//to print the pattern of pyramid
for (int j=0; j<=i; j++ )
{
System.out.print("* ");
}
System.out.println(); //to provide a line break
}
}
public static void main(String []args){
int rows = 7;
Triangle(rows);
}
}
We must note that we must print the triangle pattern with decreasing number of "*". So the initial nested for loop will decide the number space and the second nested for loop will print the "*".