본문 바로가기
Coding Test/백준

[백준 2441번 - java] 별 찍기 - 4

by olli2 2021. 11. 16.

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

 

내 답안

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[][] star = new String[n][n];
		
		//배열 초기화
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				star[i][j] = " ";
			}
		}
		
		for (int i=0; i<n; i++) {
			for (int j=n-1; j>=i; j--) {
				star[i][j] = "*";
			}
		}
		
		for (int i=0; i<n; i++) {
			System.out.println(String.join("", star[i]));
		}
	}

}