Dremendo Tag Line

Pattern printing program 54321 4321 321 using for loop in Java

for Loop - Question 15

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

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

54321
4321
321
21
1

Program

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

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

Output

54321
4321
321
21
1
video-poster