Determine whether the palindrome

// determines whether palindrome: if n = 1234321, then n is a palindrome
let readline = require("readline-sync");
let newNum = 0;
console.log ( "Please enter the number you want to judge a palindrome");
let oldNum = parseInt(readline.question(""));
// First assign oldNum to the temporary variable temp, it has been within temporary variables to be changed
// key is taken every digital temp = temp / 10 for obtaining the foregoing
for (let temp = oldNum; temp != 0; temp = parseInt(temp / 10)) {
// remove every last one pair can take more than 10
// After every ride out the next 10 to form a new number
newNum = newNum * 10 + temp % 10;
}
newNum === oldNum console.log ( 'is a palindrome'):? console.log ( 'is not a palindrome number');


Guess you like

Origin www.cnblogs.com/dbda/p/11407315.html