Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Arnold Scott   on Apr 29 In Java Category.

  
Question Answered By: Gustavo Costa   on Apr 29

1. Use a string buffer and fill it whith empty chars the length of
the diamond.

2. divide the length by two to get the midpoint

3. Use a method (think it's setChar(position, character)) to set the
last character to the midpoint.

4. create 2 variables that increment/decrement by one.

5. Each time they increment/decrement set the previous char to ' ' to
cover its tracks

6. set the other characters to the next letter at the increment/
decrement position (setChar(decrement, character2))

7. Repeat while Stringbuffers character at 0 = ' '

8. Use similar theology for bottom half of diamond

Hope this helps, i just finished a similar proggy a few weeks ago
except instead of typing a word, the user  enters a char and the width
of the diamond and the output is (assuming char is '*' and width is 5)

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

Share: 

 
 
Didn't find what you were looking for? Find more on diamond program Or get search suggestion and latest updates.


Tagged: