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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Tim Cooke
• Liutauras Vilda
• Jeanne Boyarsky
Sheriffs:
• Paul Clapham
• Rob Spoor
• Junilu Lacar
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Piet Souris
• Carey Brown
Bartenders:

# Printing a triangle

Ranch Hand
Posts: 30
• Number of slices to send:
Optional 'thank-you' note:
I couldnt get the idea to print a equilateral triangle of *s....
It should be of the form
*
* *
* * *
Please give me some idea how to get it?

Bartender
Posts: 11497
19
• Number of slices to send:
Optional 'thank-you' note:
Vinnibabu,
Welcome to the Ranch.
We do not just hand out solutions. We would rather you try on your own and learn on the way. If you have seen the other posts, you will have noticed that people post their code and other people help them figure out what is wrong with it.

It can be analyzed as follows:
1) The first line contains 1 star.
2) The second line contains 2 stars
3) The third line contains 3 stars
n) The nth line will contain n stars.

As you can see there is a pattern here. The number of stars match the line number.
Now can you tell us how you will go about solving the problem?

lowercase baba
Posts: 13086
67
• Number of slices to send:
Optional 'thank-you' note:
another hint...

it's often a good idea to break the problem down into the simplest parts you can, get that working, and only then move on.

the first thing you need to do is figure out how to print one star on one line.

Once I got that done, I'd go back and look a the requirements. I need a way to print one star, a way to print 2 stars, a way to print 3 stars...

which all sound like the same thing...i.e. a way to print X stars. so, maybe try writing a method that takes an int as a parameter, and prints that many stars...

and then keep working from there...

Vinnibabu singu
Ranch Hand
Posts: 30
• Number of slices to send:
Optional 'thank-you' note:
Thanks alot for your support.....I got my solution

Marshal
Posts: 77157
370
• Number of slices to send:
Optional 'thank-you' note:

Vinnibabu singu wrote:Thanks alot for your support.....I got my solution

Well done. Did you do it with nested for loops?

 Don't get me started about those stupid light bulbs.