Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Use "FOR" loop to create "PYRAMID" !!


This is the second "for" loop program to create design, in this post we are going to create the "Pyramid".

What do you think, Is it complicated or not? 

Of course not !!!!!!!

    
                   ^
                  ^ ^
                 ^ ^ ^
                ^ ^ ^ ^
               ^ ^ ^ ^ ^
              ^ ^ ^ ^ ^ ^
             ^ ^ ^ ^ ^ ^ ^
            ^ ^ ^ ^ ^ ^ ^ ^
           ^ ^ ^ ^ ^ ^ ^ ^ ^
          ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
        ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
      ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
     ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
    ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
   ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
  ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^


Here is the code........................................


public class Pyramid {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

int height = 20; 

for(int x=1;x<=height;x++){
for(int y=1;y<=(height-x);y++){
System.out.print(" ");
}
for(int z=1;z<x;z++){
System.out.print("^ ");
}
System.out.print("^");
System.out.println();
}
}
}


You can replace "^" with any other symbol you like. And also try to do debug of this program to understand it step by step.



This post first appeared on LET's START CORE JAVA !, please read the originial post: here

Share the post

Use "FOR" loop to create "PYRAMID" !!

×

Subscribe to Let's Start Core Java !

Get updates delivered right to your inbox!

Thank you for your subscription

×