Originally posted by surya:
Hi guys,I want to write a program which prints '*' in a diamond shape.
[This message has been edited by surya (edited July 23, 2000).]
[This message has been edited by surya (edited July 23, 2000).][/I would set it up using a "for loop", possibly a nested "for loop".]
With that said, we ARE willing to help if you have specific questions or run into problems along the way. Please post more information about what you have tried so far. This program should be short enough that you can post your actual code. Also, if you have compiler errors, post those, along with some indication of which lines in the code corresponds to the errors.
Good luck with learning Java!
On the first line of printing you call the space printing several times and the '*' printing only once.
Building toward the center of the diamond, on each line you need the '*' routine more often and the space printing routine less often.
In the midddle of the diamond you call only the '*' printing routine.
Can you do it?
So you will need to produce a diamond of spaces and *'s which looks like
So by looking at the above we can see the height and width needed in the for loop(s). By looking at the above we can also see that as long as the middle line contains an odd number greater or equal to 3 *'s we can quite easily produce a diamond.
[ November 15, 2004: Message edited by: Nigel Browne ]