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..
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)
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