Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing a triangle  RSS feed

 
Vinnibabu singu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Coming back to your problem.
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?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot for your support.....I got my solution
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinnibabu singu wrote:Thanks alot for your support.....I got my solution
Well done. Did you do it with nested for loops?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!