File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Pyramid

 
zameel amjed
Greenhorn
Posts: 14
Notepad PHP Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that possible to get Output of a pyrmid using following Array elements? :rolleyes

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



output -
^
[][]
[*][*][*]
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. But nobody's going to give you the code until you show us what you have tried so far. ShowSomeEffort
 
ankittt agarwala
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya try it out seems possible and then tell the error if you encounter any
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
Notepad PHP Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved!


Is any other methods using less FOR LOOPs..?

Thanks Ritchie
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. That looks a complicated solution.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 164
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


That's not a pyramid

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

That's a pyramid :P
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to print some spaces before your Strings. Maybe 3 spaces first time, then two, then one.
 
zameel amjed
Greenhorn
Posts: 14
Notepad PHP Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Came up with a better solution...
Used 2x spaces to arrange the pyramid in good shape....

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic