Language_Coder 552 : 반복제어문3 - 자가진단5

boom.jun.cho·2022년 4월 17일
0

Language_Coder_JUNGOL

목록 보기
103/197

문제

자연수 n을 입력받아서 다음과 같이 출력하는 프로그램을 작성하시오.

입력

3

출력

코드

package com.jungol.algorihm103;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cnt = 0;

        for(int i = 1; i <= n; i++) {
            for(int j = ((2 * n) - 1); j >= i + cnt; j--) {
                System.out.print("*");
            }
            cnt++;
            System.out.println();

            for(int j = 1; j <= i; j++) {
               System.out.print(" ");
            }
        }
        sc.close();
    }
}
profile
하루하루 최선을

0개의 댓글