Hi guys,I want to write a program which prints '*' in a diamond shape. thanks [This message has been edited by surya (edited July 23, 2000).] [This message has been edited by surya (edited July 23, 2000).]
Originally posted by surya: Hi guys,I want to write a program which prints '*' in a diamond shape. thanks [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".]
Most people around these parts are unwilling to do homework problems for others. The whole point of the assignment is so you can learn how to write a basic Java program.
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.
You could create 2 routines. 1 prints a '*' and the other prints a space. 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.
Think of what is possible. If you are writing to the command line then you will not be able to get a away with the simplest of diamonds i.e 1,2,1 because it will look like the following: * ** *
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 ]
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
a bit of art, as a gift, that will fit in a stocking