WAP to write a program usin two dimensional array to display the pattern 12345 1234 123 12 1
Answers
Answered by
5
Here's the code:
public class Pattern
{
public static void main(String[] args)
{
for(int i=5;i>0;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
Here, i and j are the loop variables.i does the job of printing 5 rows. j does the job of printing the numbers in each row.
i is kept in decreasing order, and the loop of j inherently depends on this fact. As the value of i keeps decreasing, the condition j<=i ensures that the correct numbers are printed.
Hope it helps
Purva
Brainly Community
public class Pattern
{
public static void main(String[] args)
{
for(int i=5;i>0;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
Here, i and j are the loop variables.i does the job of printing 5 rows. j does the job of printing the numbers in each row.
i is kept in decreasing order, and the loop of j inherently depends on this fact. As the value of i keeps decreasing, the condition j<=i ensures that the correct numbers are printed.
Hope it helps
Purva
Brainly Community
Similar questions