https://www.acmicpc.net/problem/13015
13015번: 별 찍기 - 23
예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.
www.acmicpc.net
소스코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
static int N;
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
for (int i = 0; i < 2*N-1; i++) {
if(i == 0 || i == 2*N-2) { //첫줄과 마지막줄
for (int j = 0; j < N; j++) {
System.out.print("*");
}
for (int j = 0; j < 2*(N-1)-1; j++) {
System.out.print(" ");
}
for (int j = 0; j < N; j++) {
System.out.print("*");
}
}else { //중간줄
int b1 = Math.abs((N-1) -i);
//첫 빈칸
for (int j = 0; j < (N-1)-b1; j++) {
System.out.print(" ");
}
//첫 별
System.out.print("*");
//두번째 빈칸
for (int j = 0; j < N-2; j++) {
System.out.print(" ");
}
//두번째 별
System.out.print("*");
//세번째 빈칸
if(!(i==N-1)) {
for (int j = 0; j < 2*(b1-1)+1; j++) {
System.out.print(" ");
}
}
//세번째 별
if(!(i==N-1)) {
System.out.print("*");
}
//네번째 빈칸
for (int j = 0; j < N-2; j++) {
System.out.print(" ");
}
//네번째 별
System.out.print("*");
}
System.out.println();
}
}
}
'Algorithm > java' 카테고리의 다른 글
백준 14503 JAVA : 로봇 청소기 (1) | 2023.02.01 |
---|---|
백준 14719 JAVA : 빗물 (0) | 2023.01.30 |
백준 10997 JAVA : 별 찍기 - 22 (0) | 2023.01.29 |
백준 10994 JAVA : 별 찍기 - 19 (0) | 2023.01.29 |
이클립스 깃허브 연동 & 백준 2557 JAVA (0) | 2023.01.27 |
https://www.acmicpc.net/problem/13015
13015번: 별 찍기 - 23
예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.
www.acmicpc.net
소스코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
static int N;
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
for (int i = 0; i < 2*N-1; i++) {
if(i == 0 || i == 2*N-2) { //첫줄과 마지막줄
for (int j = 0; j < N; j++) {
System.out.print("*");
}
for (int j = 0; j < 2*(N-1)-1; j++) {
System.out.print(" ");
}
for (int j = 0; j < N; j++) {
System.out.print("*");
}
}else { //중간줄
int b1 = Math.abs((N-1) -i);
//첫 빈칸
for (int j = 0; j < (N-1)-b1; j++) {
System.out.print(" ");
}
//첫 별
System.out.print("*");
//두번째 빈칸
for (int j = 0; j < N-2; j++) {
System.out.print(" ");
}
//두번째 별
System.out.print("*");
//세번째 빈칸
if(!(i==N-1)) {
for (int j = 0; j < 2*(b1-1)+1; j++) {
System.out.print(" ");
}
}
//세번째 별
if(!(i==N-1)) {
System.out.print("*");
}
//네번째 빈칸
for (int j = 0; j < N-2; j++) {
System.out.print(" ");
}
//네번째 별
System.out.print("*");
}
System.out.println();
}
}
}
'Algorithm > java' 카테고리의 다른 글
백준 14503 JAVA : 로봇 청소기 (1) | 2023.02.01 |
---|---|
백준 14719 JAVA : 빗물 (0) | 2023.01.30 |
백준 10997 JAVA : 별 찍기 - 22 (0) | 2023.01.29 |
백준 10994 JAVA : 별 찍기 - 19 (0) | 2023.01.29 |
이클립스 깃허브 연동 & 백준 2557 JAVA (0) | 2023.01.27 |