[Java | 백준 2440] 별찍기 - 3
· 테크· Java
Java
백준 2440번 www.acmicpc.net/problem/2440
풀이
중첩 for 문을 이용해서 풀이한다. 첫 for문은 줄 n 개 (input 값) 를 의미하고 두 번째 for 문은 * 의 개수를 하나씩 차감하는 것을 적용해준다. j 는 i 의 값에 따라 달라지므로 int j=input-i; 로 초기화해준다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import java.util.*;
public class math_2440 {
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=input-i; j>0; 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