관리 메뉴

NineTwo meet you

[백준] 2444 별 찍기 - 7 본문

프로그래밍 문제/백준

[백준] 2444 별 찍기 - 7

NineTwo 2020. 6. 25. 22:26
반응형

출처


문제

예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.

입력

첫째 줄에 N(1 ≤ N ≤ 100)이 주어진다.

출력

첫째 줄부터 2×N-1번째 줄까지 차례대로 별을 출력한다.

예제


코드

import java.util.Scanner;
public class BOJ2444 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int blank = n;
int star = -1;
//(a 개수만큼 빈칸 출력)(b 개수만큼 별 출력)(enter)
//삼각형 모양 출력
for(int i = 0; i < n; i++) {
blank--;
star+=2;
for(int j = 0; j < blank; j++) {
System.out.print(" ");
}
for(int j = 0; j < star; j++) {
System.out.print("*");
}
System.out.println();
}
//(a 개수만큼 빈칸 출력)(b 개수만큼 별 출력)(enter)
//역삼각형 모양 출력
for(int i = 0; i < n; i++) {
blank++;
star-=2;
for(int j = 0; j < blank; j++) {
System.out.print(" ");
}
for(int j = 0; j < star; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
view raw BOJ2444.java hosted with ❤ by GitHub

반응형

'프로그래밍 문제 > 백준' 카테고리의 다른 글

[백준] 2446 별 찍기 - 9  (0) 2020.06.26
[백준] 2445 별 찍기 - 8  (0) 2020.06.26
[백준] 2443 별 찍기 - 6  (0) 2020.06.25
[백준] 2442 별 찍기 - 5  (0) 2020.06.25
[백준] 2441 별 찍기 - 4  (0) 2020.06.25
Comments