SHARE
TWEET

Untitled

a guest Oct 20th, 2019 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static void print(int h) {
  2.         int lineStartIndex = h / 2;
  3.         int lineEndIndex = h - 1;
  4.  
  5.         for (int lineIndex = 0; lineIndex < h; lineIndex++) {
  6.             // print line
  7.             for (int columnIndex = 0; columnIndex < h; columnIndex++) {
  8.                 if (columnIndex < lineStartIndex || columnIndex > lineEndIndex)
  9.                     System.out.print(' ');
  10.                 else if (columnIndex == lineStartIndex || columnIndex == lineEndIndex
  11.                         || lineIndex == 0 || lineIndex == h - 1)
  12.                     System.out.print('*');
  13.                 else
  14.                     System.out.print('#');
  15.             }
  16.  
  17.             if (lineIndex < h / 2 - 1) {
  18.                 lineEndIndex--;
  19.             }
  20.             else if (lineIndex == h / 2 - 1) {
  21.                 lineStartIndex = h / 2 - 1;
  22.                 lineEndIndex = h / 2 - 1;
  23.             }
  24.             else {
  25.                 lineStartIndex--;
  26.             }
  27.  
  28.             System.out.println();
  29.         }
  30.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top