[프로그래머스 lv.0] 덧셈식 출력하기

username_oy·2023년 6월 13일

프로그래머스

목록 보기
3/4

📌문제설명

두 정수 a, b가 주어질 때 다음과 같은 형태의 계산식을 출력하는 코드를 작성해 보세요.

 a + b = c

❗ 제한사항

  • 1 ≤ a, b ≤ 100

입출력 예

입력 #1

 4 5

출력 #1

 4 + 5 = 9

💭나의 생각

템플릿 리터럴을 사용하여(${}) 문자열 '4 + 5 = 9 '로 출력

  • ${}의 결과는 문자열로 자동 변환됨

✍풀이

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = line.split(' ');
}).on('close', function () {
    console.log(`${Number(input[0])} + ${Number(input[1])} = ${Number(input[0])+ Number(input[1])}`);
});

다른 풀이 참고

const readline = require('readline')
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
}).on('line', function (line) {
    const [a, b] = line.split(' ')
    console.log(a, '+', b, '=', Number(a) + Number(b))
})

배열의 비구조화 할당을 사용한 것으로 보이는데..

profile
프런트엔드 개발자로의 여정

0개의 댓글