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

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 = 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();
		}
		
		// 아래쪽
		for (int i = 1; i <= N-1; i++) {
			
			for (int j = 1; j <= i; j++) {
				System.out.print(" ");
			}
			for (int j = 1; j <= N-i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}

	}

}
728x90

+ Recent posts