1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | static void pyramid(int size){ char[] chars = new char[size*2]; Arrays.fill(chars, ' '); chars[size] = '*'; StringBuilder sb = new StringBuilder(); sb.append(chars).append('\n'); int index = size; while((index -= 2) > 0) { chars[index] = '*'; chars[size*2 - index] = '*'; sb.append(chars).append('\n'); } System.out.println(sb); } |
styled using hilite.me
No comments:
Post a Comment