문제 설명 두 개의 문자열 str1, str2가 공백으로 구분되어 입력으로 주어집니다. 입출력 예와 같이 str1과 str2을 이어서 출력하는 코드를 작성해 보세요. 제한사항 1 ≤ str1, str2의 길이 ≤ 10 입출력 예 입력 #1 apple pen 출력 #1 applepen 입력 #2 Hello World! 출력 #2 HelloWorld!
이론 입력받기 const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let input = []; rl.on('line', function (line) { input = line.split(' '); }); split() 함수를 사용해서 공백을 기준으로 문자열을 나눠요. 입력 #1을 기준으로 input[0]에는 apple이, input[1]에는 pen이 들어가요. 출력하기 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 () { const [str1, str2] = input; console.log(str1 + str2); }); 문자열을 더하면 문자열이 이어져요. applepen이 출력돼요.코드 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 () { const [str1, str2] = input; console.log(str1 + str2); });