백준 2442번: 별 찍기 - 5 [입출력] - Java :: 매운코딩
728x90
300x250

www.acmicpc.net/problem/2442

 

2442번: 별 찍기 - 5

첫째 줄에는 별 1개, 둘째 줄에는 별 3개, ..., N번째 줄에는 별 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 = 1; i <=N; i++) {
			
			for (int j = 1; j <= N-i; j++) {
				System.out.print(" ");
			}
			
			for (int j = 1; j <= 2*i-1; j++) {
				System.out.print("*");
			}
			
			
			System.out.println();
		}
	}

}
728x90

+ Recent posts