• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing a triangle

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot for your support.....I got my solution
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic