백준 #10996번 별 찍기 - 21

jhj·2025년 1월 18일

백준 JAVA

목록 보기
551/583
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++) {
			if(n % 2 == 0) {
				for(int j = 0; j < n / 2; j++) {
					System.out.print("* ");
				}
				System.out.println();
			}else {
				for(int j = 0; j < (n + 1) / 2; j++) {
					System.out.print("* ");
				}
				System.out.println();
			}
			for(int j = 0; j < n / 2; j++) {
				System.out.print(" *");
			}
			System.out.println();
		}
		sc.close();
	}
}
profile
개발자를 꿈꾸는

0개의 댓글