알고리즘

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

muerha 2024. 11. 22. 21:07

 

 

 

 


 

 

나의 풀이

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 x = 0; x < b ; x++){
            for(int y = 0 ; y < a ; y++){
                System.out.print("*");
            }
            System.out.println();
        }
        
    }
}

 

 

 

 

 

다른 사람의 풀이

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();
        String str = "";
        for(int i=0 ; i<b; i++){
            for(int j = 0; j<a; j++){
                str += "*";
            }
            str+="\n";
        }
        System.out.println(str);
    }
}