Loading...
Loading...
Loading...
Print a diamond of stars with n rows in its top half. The top half is a centred pyramid: row i has n - i spaces and then 2i - 1 stars. The bottom half is the same pyramid upside down, without repeating the widest row.
Example
Input
3
Output
* *** ***** *** *
Rows of 1, 3, 5, 3 and 1 stars, centred.
Try the problem first. Open one hint at a time.
Solve the top half first: a centred pyramid. Write down, for n = 3, how many spaces and stars each row has.
Each row is two inner loops: one for the spaces, one for the stars.
The bottom half uses the same two inner loops, with the row going from n - 1 down to 1.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor