본문 바로가기

코딩 테스트

[프로그래머스] (Lv.1) 직사각형 별찍기

728x90

문제


이 문제에는 표준 입력으로 두 개의 정수 n과 m이 주어집니다.
별(*) 문자를 이용해 가로의 길이가 n, 세로의 길이가 m인 직사각형 형태를 출력해보세요.

 

-  출력 예시  -

정답 코드


import java.util.Scanner;

class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        for(int i=0; i<b; i++) {
            for(int j=0; j<a; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

 

이것을 주의하자!


가장 정석인 방법은 '중첩 for문'으로 구현하는 것이다.

특별한 포인트는 없이 간단하다!