fork download
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.io.OutputStreamWriter;
  6.  
  7. public class Main {
  8. static char[][] str = null;
  9.  
  10. public static void main(String[] args) throws NumberFormatException, IOException {
  11.  
  12.  
  13. int n = Integer.parseInt(bf.readLine()); // 3*2^k (3, 6, 12, 24, 48, ...) (k<=10)
  14.  
  15. str = new char[n][2*n-1]; // x,y 2차원 그림판 ... 수직방향이 x축, 수평이 y축 임...
  16.  
  17. drawStar(0,n-1,n);
  18.  
  19. for (int i = 0; i < n; i++) {
  20. bw.write(str[i]);
  21. bw.write('\n');
  22. }
  23.  
  24. bw.flush();
  25. bw.close();
  26.  
  27. }
  28.  
  29. /**
  30. * 삼각형을 그리는 재귀함수
  31. * @param x 삼각형을 꼭대기 x 좌표
  32. * @param y 삼각형을 꼭대기 y 좌표
  33. * @param n 삼각형 높이
  34. */
  35. public static void drawStar(int x, int y, int n) {
  36. if (n == 3) {
  37. str[x][y] = '*'; // 1번째 줄
  38. str[x+1][y-1] = str[x+1][y+1] = '*'; // 2번째 줄
  39. str[x+2][y-2] = str[x+2][y-1] = str[x+2][y] = str[x+2][y+1] = str[x+2][y+2] = '*'; // 3번째줄
  40. return;
  41. }
  42.  
  43. drawStar(x,y,n/2);
  44. drawStar(x+ n/2,y-n/2,n/2);
  45. drawStar(x+ n/2,y+n/2,n/2);
  46. }
  47.  
  48. }
Success #stdin #stdout 0.04s 4575232KB
stdin
24
stdout
*
**
*****
**
****
**********
**
****
**********
****
********
********************
**
****
**********
****
********
********************
****
********
********************
********
****************
****************************************