Dremendo Tag Line

Pattern printing program 1 21 321 using for loop in Java

for Loop - Question 14

In this question, we will see how to print the pattern 1 21 321... in Java programming using for loop. To know more about for loop click on the for loop lesson.

Q14) Write a program in Java to print the pattern given below using for loop.

1
21
321
4321
54321

Program

public class Q14
{
    public static void main(String args[])
    {
        int r,c;

        for(r=1; r<=5; r++)
        {
            for(c=r; c>=1; c--)
            {
                System.out.print(c);
            }
            System.out.println();
        }
    }
}

Output

1
21
321
4321
54321
video-poster