본문 바로가기

코드테스트/Java

프로그래머스 - Level 1, java

1. 문제 설명

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

 

- 제한 조건 :  n과 m은 각각 1000이하인 자연수

 

import java.util.Scanner;

public 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 = 1; i <= b; i++){ // i가 b보다 작거나 같을 때, For문 실행
            for(int j = 1; j <= a; j++){ //j가 a보다 작거나 같을때, * 찍기
                System.out.print('*');
            }
        System.out.println(); // 첫번째 for문이 끝나면 줄바꿈 처리
        }
    }
}