Pyramid Pattern–Nested Loop-1

pyramid pattern java program

In this image, we found 12 different programs on pyramid pattern. But Logic of all programs is same.

Let’s understand one program and create that program in this blog.

pyramid pattern java program

This is our program image.

Before starting on this program, you must have to knowledge of nested, pattern and logical nested loop.

Let’s see why we need?

First Step: Create Left Alignment Pattern Program

5
54
543
5432
54321

 

for(int i=5;i>=1;i–)           // Step of above example

{

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

                {

                                System.out.print(j);

}

System.out.println();

}





 

Second Step: Create Right Alignment Pattern Program using K loop.

5
54
543
5432
54321

 

int sp=4;

for(int i=5;i>=1;i–)           // Step of above example

{

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

                {

                System.out.print(“ ”);    // 1 space

}

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

                {

                                System.out.print(j);

}

System.out.println();

sp–;

}

 

Third Step: Create Pyramid Pattern Program using single space.

Just Change System.out.print(j);  line into System.out.print(“ ”+j);  // 1 Space before or after j variable.

 

 




If you have problem on this blog, you can directly comment on it. This tutorial will help you understand the concepts of java loop programs.

Share and Enjoy

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

690total visits,21visits today


mayank

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

Related articles

2 Comments

  1. November 1, 2016 - 4:23 am

    I’m just writing to let you know of the exceptional discovery my princess gained reading your web page. She noticed several things, which include what it’s like to have a very effective coaching mindset to get many others completely thoroughly grasp chosen tortuous subject areas. You really exceeded our expectations. Many thanks for supplying these priceless, trustworthy, revealing and also unique thoughts on this topic to Janet.

  2. November 5, 2016 - 4:27 am

    I in addition to my friends were found to be looking through the great suggestions on your site and then then developed a terrible feeling I never expressed respect to you for those strategies. Those people happened to be as a consequence stimulated to learn them and have now pretty much been using those things. Thank you for really being quite accommodating as well as for obtaining certain really good tips most people are really needing to be aware of. Our sincere apologies for not saying thanks to you earlier.

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