[Programmers]직사각형 별찍기

이묘·2022년 7월 19일
0

CodingTest

목록 보기
12/41
post-thumbnail

프로그래머스 코딩테스트 1단계



소스코드

process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
    const n = data.split(" ");
    const a = Number(n[0]), b = Number(n[1]);
  	// 위에코드는 대강 '\n'을 쓸 수 있게 해주는 것들과
  	// 입력예시로 들어온 코드를 각각 잘라주는 것 같다.

    var star='';
    for (let i = 0; i < n.length; i++){
        for(let j = 0; j<a; j++){
            star+='*'
        }
        star += '\n';
    }
    console.log(star);

    // repeat를 사용해서 더 간결하게 코드를 짤 수도 있다.
    // star = '*'.repeat(a)+'\n'
    // console.log(star.repeat(b))

});
profile
본질을 공부해야 응용도 하지 않을까

0개의 댓글

Powered by GraphCDN, the GraphQL CDN