NEED HELP! w/programing.

drdallon

New Member
Okay so i have an assignment due 3 days ago in programing, i was sick and couldnt get around to doing it all. I can still turn it in but i need some help i cannot for the life of me figure out how to code this.

The assignment is:

4) Write a class named MakeAPattern that reads a number of lines from the user then makes a pattern of stars in the Run I/O window as follows: If the user enters 7, the output should look exactly like:

*******

******

*****

****

***

**

*

The ‘algorithm’ is: the top line has the same number of stars as the user entered. The next line has one fewer stars, and so on. The last line has only one star.

Hints: You need a nested loop to do this. For the outside loop, use the variable holding the value you read from the user as your counter, and decrement the counter inside the loop instead of incrementing it as we normally do. Use a different counter for the inner loop and initialize it to the value currently held in the outer loop counter.

Finally, use:

System.out.print(‘*’) // caution: not java single quotes

to print a single star and System.out.println() to print an end-of-line.

We are using jGRASP. If some one could code or, or atleast point me in the right direction that would be a HUGE help!

Thank you!
 

Yoonsi

New Member
Ill help you out if you can clarify what you mean by this comment:
"// caution: not java single quotes"
 

footballstevo75

Active Member
Ill help you out if you can clarify what you mean by this comment:
"// caution: not java single quotes"

I'm assuming it's because it's supposed to be a char? EDIT- nevermind I'm just as confused as you lol.

So this is pretty easy. You need to get an int from the user as to how many stars they want in the first line. Then do this as stated-
"Hints: You need a nested loop to do this. For the outside loop, use the variable holding the value you read from the user as your counter, and decrement the counter inside the loop instead of incrementing it as we normally do. Use a different counter for the inner loop and initialize it to the value currently held in the outer loop counter."

Then in the inner loop print out the asterisk, and for some reason do a print then println for a space, even though you could just do System.out.println('*');
and it would do the same thing.
 
Top