티스토리 뷰

알고리즘/문제풀이

[BOJ-2439] 별 찍기 - 2

개발하고싶은개발자 2023. 8. 27. 13:42

먼저 공백을 print하고 *을 프린트 해주면 된다

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

class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n - i; j++)
                System.out.print(" ");
            for (int j = 1; j <= i; j++)
                System.out.print("*");
            System.out.println("");
        }
    }
}

문제링크

'알고리즘 > 문제풀이' 카테고리의 다른 글

[BOJ-1011] Fly me to the Alpha Centauri  (0) 2023.11.24
[BOJ-1271] 엄청난 부자2  (0) 2023.08.26
[BOJ-1000] A+B  (0) 2023.08.26
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30