[프로그래머스] Level 0. 문자열 붙여서 출력하기

이서연·2023년 11월 5일
0

프로그래머스

목록 보기
6/10

문제 설명

두 개의 문자열 str1, str2가 공백으로 구분되어 입력으로 주어집니다.
입출력 예와 같이 str1과 str2을 이어서 출력하는 코드를 작성해 보세요.

제한사항

1 ≤ str1, str2의 길이 ≤ 10

입출력 예

입력 #1
apple pen
출력 #1
applepen
입력 #2

Hello World!
출력 #2

HelloWorld!

Solution.js

Solution (1)

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 () {
    str1 = input[0];
    str2 = input[1];
    console.log(str1+str2)
});

Solution (2)

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 () {
    str1 = input[0];
    str2 = input[1];
    console.log(str1.concat(str2))
});

str1 + str2
문자열끼리 합칠때 +를 이용하면 합칠 수 있다.

str1.concat(str2)
문자열 str1에 concat를 이용해서 str2를 합칠 수 있다.

0개의 댓글