Right Alignment Pattern

right alignment

This four programs work on this basic logic. This is called right alignment program in nested loop program.

Before this program, we have to know about left alignment program. We already know left alignment programs in our pattern examples.

class loop13

{

            public static void main(String args[])

            {

                        int i;

                        int j;

                        int k,sp=0;

                        for(i=1;i<=5;i++)

                        {

                                    for(k=1;k<=sp;k++)

                                    {

                                                System.out.print(” “);

                                    }

                                    for(j=5;j>=i;j–)

                                    {

                                                System.out.print(j);

                                    }          

                                    System.out.println();

                                    sp++;             

                        }

            }

}

 

Output:

54321

  5432

    543

      54

        5


right alignment

 

This four right alignment program works on this basic logic. So enjoy all right alignment program. You can also do * pattern program here. Next blog we will introduce pyramid patter program.

 

class loop14

{

                public static void main(String args[])

                {

                                int i;

                                int j;

                                int k,sp=4;

                                for(i=5;i>=1;i–)

                                {

                                                for(k=1;k<=sp;k++)

                                                {

                                                                System.out.print(” “);

                                                }

                                                for(j=5;j>=i;j–)

                                                {

                                                                System.out.print(j);

                                                }             

                                                System.out.println();

                                                sp–;                      

                                }

                }

}

Output:

        5

      54

    543

  5432

54321


 

1268total visits,4visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

3 responses to “Right Alignment Pattern”

  1. I see a lot of interesting posts here. Your
    blog can go viral easily, you need some initial traffic only.
    How to get initial traffic? Search for: masitsu’s viral method

  2. I see your page is in the same niche like my weblog. Do you allow guest posting?
    I can write excellent posts for you. Let me know if you are interested.

    • In basic topic, we do not need guest posting..

      But in advance level we will work with expert guest for posting..

      Thank you for valuable comment.