원하는대로

관심분야에 대해 원하는 모든 것을 발행하는 곳

미정 자세히보기

공부 스걱스걱/코딩테스트

[백준] 10996번_ 별찍기

ohsoou 2022. 1. 12. 13:32
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		int input = new Scanner(System.in).nextInt();
		main(input);
		
	}
	
	public static void main(int input) {
		String str = "";
		
		for(int i = 0; i < input; i++) {
			for(int j = 1; j<= input; j++) {
				if(j == 1) {
					str += "*";
				} else if (input == 2) {
					str += "\n *";
				}else if(input % 2 == 0 && j == input / 2) {
					str += " *\n";
				} else if (input % 2 != 0 && j == (input / 2) + 1) {
					str += " *\n";
				} else {
					str += " *";
				}
			}
			
			str += "\n";
		}
		
		System.out.print(str);
	}
}

좋지 않은 풀이

더 좋은 풀이를 생각해봐야겠다.