programmers/Lv.1

[프로그래머스] 직사각형 별찍기

ssk1 2024. 3. 21. 12:54
728x90
문제
풀이

 

이중 for문을 사용하여

첫번째 for문은 열, 두번째 for문은 행.

 

답안
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 = 1; i <= b; i++){
            for(int j = 1; j <= a; j++){
                System.out.print("*");       
            }
            System.out.println();
        }
    }
}
728x90