Loading...
Loading...
Loading...
Print a centred pyramid of letters with n rows. Row i has n - i spaces, then the letters from A up to the i-th letter, then back down to A:
`` A ABA ABCBA ``
Example
Input
4
Output
A ABA ABCBA ABCDCBA
The last row is ABCDCBA.
Try the problem first. Open one hint at a time.
Each row has three parts: spaces, letters going up, letters going down.
Going up, print A to the i-th letter. Going down, start one letter below the top so it is not printed twice.
Use a char loop variable: for (char c = 'A'; c < 'A' + i; c++).
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor