• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
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
 
Marshal
Posts: 5931
411
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
Marshal
Posts: 5931
411
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are most welcome
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!