๐Ÿค ์€์ง€log ๐Ÿค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ํ™€์ง ๊ตฌ๋ถ„ํ•˜๊ธฐ ๋ณธ๋ฌธ

๐ŸŒˆ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค:Javascript] ํ™€์ง ๊ตฌ๋ถ„ํ•˜๊ธฐ

Eun_zii 2024. 4. 11. 15:50

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv.0

- ํ™€์ง ๊ตฌ๋ถ„ํ•˜๊ธฐ

 

๐Ÿ’š ๋ฌธ์ œ์„ค๋ช…

 

๐Ÿ’š ์ œํ•œ์กฐ๊ฑด

  • 1 ≤ n ≤ 1,000

๐Ÿ’š ํ’€์ด

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 () {
    n = Number(input[0]);

    if (n % 2 === 0) {
        console.log(`${n} is even`);
    } else {
        console.log(`${n} is odd`);
    }
});

 

โœ… 

NodeJS์˜ readline ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋ฐ›๊ณ , ๊ทธ ์ž…๋ ฅ์ด ์ง์ˆ˜์ธ์ง€ ํ™€์ˆ˜์ธ์ง€๋ฅผ ํŒ๋ณ„ํ•˜์—ฌ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•ด์•ผํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

(์‚ฌ์‹ค ๊ธฐ์กด์— ํ’€๋˜ ๋ฌธ์ œ๋“ค์ด๋ž‘ ๋‹ฌ๋ผ์„œ ์‚ด์ง ๋‹นํ™ฉ ; ใ…Žใ…Ž.. ; )

 

๊ทธ๋ž˜๋„ output์„ ๋‚ด๋ณด๋‚ด๋ฉด ๋˜๋Š”๊ฒƒ ๊ฐ™์•˜๊ณ , if( )๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ n์ด ์ง์ˆ˜์ธ์ง€ ํ™€์ˆ˜์ธ์ง€๋ฅผ ํŒ๋ณ„ํ•œํ›„,

์ง์ˆ˜์ด๋ฉด "n is even"์„, ํ™€์ˆ˜์ด๋ฉด "n is odd"๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

728x90