This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Array Pyramid Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 3011
    
    9
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: 32708
    
    4
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: 32708
    
    4
Yes. That looks a complicated solution.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
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: 32708
    
    4
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Array Pyramid
 
Similar Threads
Array Question
Reference to NOT an element of an array
Printing a primitive array
Random ()
Carriage return in a JOptionPane