Let's analyze the pattern. There are 5 rows. So, we must have a loop running 5 times.
Now, each line has a decreasing sequence. The sequence decreases all the way to 1. We must use an inner loop, whose end condition would be greater than 0. Also, inner loop variable must decrement by 2.
Now, the only thing varying on each line is the start point. The start point keeps on decreasing. So, the inner loop starting condition must somehow depend on the outer loop variable.
Answers & Comments
Verified answer
Simple Pattern - Java
Let's analyze the pattern. There are 5 rows. So, we must have a loop running 5 times.
Now, each line has a decreasing sequence. The sequence decreases all the way to 1. We must use an inner loop, whose end condition would be greater than 0. Also, inner loop variable must decrement by 2.
Now, the only thing varying on each line is the start point. The start point keeps on decreasing. So, the inner loop starting condition must somehow depend on the outer loop variable.
Here's a Program Code.
Program Code - SimplePattern.java
public class SimplePattern
{
public static void main(String[] args)
{
//Create Outer Loop to run 5 times for 5 lines
for(int i = 5; i > 0; i--)
{
/* Set Inner Loop
* We set inner loop initial condition as
* j = 2i - 1
* Decrement is j = j - 2.
*/
for(int j = (2*i)-1; j > 0; j = j - 2)
{
System.out.print(j+" ");
}
//Print new line after each row
System.out.println();
}
}
}
brainly.in/app/profile/6418961