백준 2444번 별 찍기 - 7(java)

마뇽미뇽·2024년 5월 6일
0

알고리즘 문제풀이

목록 보기
60/165

1.문제


https://www.acmicpc.net/problem/2444

2.풀이

3.코드

package com.example.baekjoon;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

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

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

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

            for(int k = 2 * i - 1; k >= 1; k--){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
profile
Que sera, sera

0개의 댓글