Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void print(int h) {
- int lineStartIndex = h / 2;
- int lineEndIndex = h - 1;
- for (int lineIndex = 0; lineIndex < h; lineIndex++) {
- // print line
- for (int columnIndex = 0; columnIndex < h; columnIndex++) {
- if (columnIndex < lineStartIndex || columnIndex > lineEndIndex)
- System.out.print(' ');
- else if (columnIndex == lineStartIndex || columnIndex == lineEndIndex
- || lineIndex == 0 || lineIndex == h - 1)
- System.out.print('*');
- else
- System.out.print('#');
- }
- if (lineIndex < h / 2 - 1) {
- lineEndIndex--;
- }
- else if (lineIndex == h / 2 - 1) {
- lineStartIndex = h / 2 - 1;
- lineEndIndex = h / 2 - 1;
- }
- else {
- lineStartIndex--;
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement