import java.util.Scanner;
class ReverseReducingHalfTriangle
{
static void reverseReducingHalfTriangle()
{
int height = 9;
//Run the outer for loop for 5 times, to print 5 rows.
for(int i = 0; i<5; i++)
{
//Reset height to 9 after each iteration of the inner loop.
height = 9;
//Run the inner for loop as many times as the value of 'i'.
for(int j = 0 ; j <= i ; j++)
{
//Print values from 9, reducing by 2 in each iteration. Number of iterations = 'i'.
System.out.print(height);
height -= 2;
}
//Introduce a new line after each iteration of the inner loop.
System.out.println();
}
}
public static void main(String[] args)
{
reverseReducingHalfTriangle();
}
}
Output:
.png)
No comments:
Post a Comment