| 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
|
|
|
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
|
|
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
|
|
|
Yes. That looks a complicated solution.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
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
|
|
|
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....
|
 |
 |
|
|
subject: Array Pyramid
|
|
|