본문 바로가기

배운 거/Algorithm

[연습문제]별찍기

주어진 변수 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();
        String A = "";
        for(int i = 0; i <a;i++){ A +="*";}
        for(int j = 0; j <b; j++){System.out.println(A);}
    }
}

우선 String 변수를 만들어주고 n개만큼의 별을 추가해줬다

그리고 m번만큼 out 해주었다

 

연산이 오래 걸리는 게 아니라 그냥 for구문 두번으로 처리해도

 

효율성이 그렇게 떨어지지는 않은거 같음.