• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the logic behind displaying * in pyramid style ?  RSS feed

 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

All,

off late while preparing for OCAJP8 i was dabbling with array's and there came a question(this is the most frequently asked question in interview) displaying */$ in pyramid style. I have searched over the internet for the logic but instead got code. Could any one please explain the logic in general so that i can try out in different ways of writing it. I understood the code but not the logic..



Thanks
 
Liutauras Vilda
Sheriff
Posts: 4922
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi krishnadhar Mellacheruvu,

Well, probably it is worth to mention, that non of such questions should come up on OCAJP exam, at least I didn't find nothing like that in couple of books I read about certifications.

Now regarding this code snippet. Not much here probably is to explain, maybe writing down couple of tables by tracking down variables would help to visualize this, BUT in short, this is how I think about that program without bothering a lot about the code:
During the first iteration it prints 5 spaces AND $
During the second iteration 4 spaces and two $$
During the third iteration 3 spaces and three $$$
And so on..

Basically each iteration reducing amount of spaces and increasing amount of dollars (latter probably is mostly exciting)

Is it what you expected?
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Liutauras,

This question does not come in the certifications but in general as a job interview question which i encountered while dabbling in depth about array's. And yes this is what i was looking for to be precise. Thanks for the reply
 
Liutauras Vilda
Sheriff
Posts: 4922
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are most welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!