File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Array Pyramid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array Pyramid" Watch "Array Pyramid" New topic
Author

Array Pyramid

zameel amjed
Greenhorn

Joined: Feb 16, 2011
Posts: 14

Is that possible to get Output of a pyrmid using following Array elements? :rolleyes

String x[] ={"[*]","[]","^"};



output -
^
[][]
[*][*][*]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3446
    
  12
Yes. But nobody's going to give you the code until you show us what you have tried so far. ShowSomeEffort


Joanne
ankittt agarwala
Ranch Hand

Joined: Jan 19, 2011
Posts: 42
ya try it out seems possible and then tell the error if you encounter any
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38334
    
  23
Welcome to the Ranch

Yes, it is possible, but I suggest you try this first, to get the print-out you want. I think that will be easier.
zameel amjed
Greenhorn

Joined: Feb 16, 2011
Posts: 14

Solved!


Is any other methods using less FOR LOOPs..?

Thanks Ritchie
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38334
    
  23
Yes. That looks a complicated solution.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38334
    
  23
What you want is to count up to three, and for each of those numbers print out the array member that many times. So you need two loops nested inside each other, if you use the array I showed you earlier. It is a bit more complicated because arrays start at no 0.
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164

^
[][]
[*][*][*]


That's not a pyramid

     /\
    [][]
[*][*][*]

That's a pyramid :P
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38334
    
  23
You will need to print some spaces before your Strings. Maybe 3 spaces first time, then two, then one.
zameel amjed
Greenhorn

Joined: Feb 16, 2011
Posts: 14

Came up with a better solution...
Used 2x spaces to arrange the pyramid in good shape....

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array Pyramid