프로그래머스/lv0

직각삼각형 출력하기

do_it0904 2022. 12. 5. 09:59
/* 직각삼각형 출력하기
 * "*"의 높이와 너비를 1이라고 했을 때,
 * "*"을 이용해 직각 이등변 삼각형을 그리려고합니다.
 * 정수 n 이 주어지면 높이와 너비가 n 인 직각 이등변 삼각형을 출력하도록
 *
 * 3
 * *
 * **
 * ***
 */

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.Scanner;
public class programmer_0_60 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
 
        /* 다른사람 풀이
        for(int i=1; i<=n; i++){
            System.out.println("*".repeat(i));
        }
        */
        for(int i = 1; i <= n; i++){
            for(int k = 1; k <= i; k++System.out.print("*");
            System.out.println("");
        }
        System.out.println("rst = " + n);
    }
}
 
cs