<오답> : 힌트 2차원 배열을 활용해 보자.
package doit.chap5.실습;
import java.util.*;
public class Main {
static String pattern(int n) {
String head;
String body;
String bottom;
if (n == 3) {
head = "***";
body = "* *";
bottom = "***";
} else {
head = pattern(n / 3).repeat(n / 3);
body = pattern(n / 3) + pattern(n / 3).replace("*", " ") + pattern(n / 3);
bottom = pattern(n / 3).repeat(n / 3);
}
return head + "\n" + body + "\n" + bottom;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.print(pattern(n));
}
}
728x90
반응형
'매일코테 > 못 푼 문제' 카테고리의 다른 글
조합 0의 개수 - 시간초과 (0) | 2022.08.14 |
---|---|
백준 14단계 5번 (0) | 2022.08.12 |
참외밭 (2) | 2022.08.06 |
백준 12단계 no.4 (0) | 2022.08.05 |
백준 10단계 no.4 (0) | 2022.07.26 |