[Java | 백준 2442] 별찍기 - 5
· 테크· Java
Java
백준 2442 www.acmicpc.net/problem/2442
풀이
트리모양으로 별을 찍는 문제이다. 왼쪽 공간을 생각해보면 백준 별찍기-3 의 문제와 같이 줄어드는 공백으로 된 삼각형이 있는 것을 알 수 있다. 트리가 출력될 때 공백과 별을 함께 출력한다고 생각해보자.
결과적으로 공백은 한 개씩 줄어들고, 별은 n*2-1 만큼 출력된다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import java.util.*;
public class math_2442 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
sc.nextLine();
for (int i=0; i<input; i++) {
for (int j=i+1; j<input; j++) {
System.out.print(" ");
}
for (int j=input-i*2; j<input+1; j++) {
System.out.print("*");
}
System.out.print("\n");
}
sc.close();
}
}
|
cs |
Comments
No comments yet. Be the first!
319 posts in 테크
- 368Supabase 프로젝트 복사하기 (Restore to a New Project)NEW
- 341Migrating from Permanent Access Tokens to Token Exchange — Why Order Matters
- 326Startup & Product Glossary: Terms Every Solo Founder Should Know
- 325Context Management — How I Do It Now
- 324Claude Code Routines vs Cowork Schedule — What's the Difference?
1–5 / 319