Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with loop constructs

 
Khair Bahir
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to design a program that will display the following:

*****
****
***
**
*

I'm sure there is some way to use loop constructs to make even 100 rows of the previous message, but I'm not sure how.

I was thinking of using a 'for' construct to generate numbers from 5 to 1, and then assigning each number to a certain number of *, but even this I don't know how to do.

Is there a better approach?

Thanks.
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Your approach sounds about right. Try coming up with a pseudocode which would detail every step of the program.

then assigning each number to a certain number of *

This would be another 'for' construct within the original 'for'.
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search the forums as well. I think there was a similar post sometime last week.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic