2444번: 별 찍기 - 7

문제.

예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.

입력

첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다.

출력

첫째 줄부터 2×N-1번째 줄까지 차례대로 별을 출력한다.

예제 입력 & 예제 출력

5
  	*
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *

코드

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader reader =
      new BufferedReader(new InputStreamReader(System.in));

    int N = Integer.parseInt(reader.readLine());
    // 총 칸 수 = 2 * N -1 
    
    // 이중 반복문 - 오름차순
    for (int i = 1; i <= N; i++) {
      for (int j = 0; j < N-i; j++) System.out.print(" ");
      for (int j = 0; j < 2 * i - 1; j++) System.out.print("*");
      System.out.println();
    }

    // 이중 반복문 - 내림차순
    for (int i = N-1; i >= 1; i--) {
      for (int j = 0; j < N-i; j++) System.out.print(" ");
      for (int j = 0; j < 2 * i - 1; j++) System.out.print("*");
      System.out.println();
    }
  }
}