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


 

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

784total visits,7visits today


mayank

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

Related articles

3 Comments

  1. October 5, 2016 - 12:01 am

    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. November 12, 2016 - 1:21 pm

    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.

    • November 12, 2016 - 1:38 pm

      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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image

EmailEmail
PrintPrint