백준 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
댓글