본문 바로가기
백준(Baekjoon)

[백준] 2522번: 별 찍기 - 12 - 자바

by IT 정복가 2022. 5. 1.
728x90

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

 

2522번: 별 찍기 - 12

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

www.acmicpc.net

[문제]


[코드]

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 = 0; i < n; i++) {
			for(int j = n; j > i+1; j--) 
				System.out.print(" ");
			
			for(int k = 0; k < i+1; k++)
				System.out.print("*");
			System.out.println();
		}
		
		for(int i = 0; i < n-1; i++) {
			for(int j = 0; j < i+1; j++)
				System.out.print(" ");
			for(int k = i; k < n-1; k++)
				System.out.print("*");
			System.out.println();
		}
		sc.close();
	}
}

[결과]

728x90