設n是一任意天然數。若將n的各位數字反向排列所得天然數n1與n相等,則稱n爲一回文數。ui
//迴文數 let readline = require("readline-sync"); console.log("請輸入數字:"); let num = parseInt(readline.question("")); let newNum = 0; for(temp=num;temp!=0;temp=parseInt(temp/10)){ newNum = newNum*10+temp%10; } newNum===num?console.log("是迴文數"):console.log("不是迴文數");