5位数判断
//给出一个不超过5位的正整数,要求:
//1.求出它是几位数 2.分别打印出每一位数字 3.按逆序打印出各位数字
let readline = require("readline-sync");
console.log("请输入数字")
let num = parseInt(readline.question(""));
if (num > 99999 || num < 0) {
console.log("你输入的数字不符合要求");
}
else if (parseInt(num / 10000) > 0) {
let wan = parseInt(num / 10000);
let qian = parseInt(num % 10000 / 1000);
let bai = parseInt(num % 1000 / 100);
let shi = parseInt(num % 100 / 10);
let ge = parseInt(num % 10);
console.log("这是一个5位数");
console.log("数字为:", num);
console.log("万位:", wan, "千位", qian, "百位", bai, "十位", shi, "个位", ge);
let newNum = ge * 10000 + shi * 1000 + bai * 100 + qian * 10 + wan
console.log("逆序输出为:", newNum);
}
else if (parseInt(num / 1000) > 0) {
let qian = parseInt(num % 10000 / 1000);
let bai = parseInt(num % 1000 / 100);
let shi = parseInt(num % 100 / 10);
let ge = parseInt(num % 10);
console.log("这是一个4位数");
console.log("数字为:", num);
console.log("千位", qian, "百位", bai, "十位", shi, "个位", ge);
let newNum = ge * 1000 + shi * 100 + bai * 10 + qian;
console.log("逆序输出为:", newNum);
}
else if (parseInt(num / 100) > 0) {
let bai = parseInt(num % 1000 / 100);
let shi = parseInt(num % 100 / 10);
let ge = parseInt(num % 10);
console.log("这是一个3位数");
console.log("数字为:", num);
console.log("百位", bai, "十位", shi, "个位", ge);
let newNum = ge * 100 + shi * 10 + bai;
console.log("逆序输出为:", newNum);
}
else if (parseInt(num / 10) > 0) {
let shi = parseInt(num % 100 / 10);
let ge = parseInt(num % 10);
console.log("这是一个2位数");
console.log("数字为:", num);
console.log("十位", shi, "个位", ge);
let newNum = ge * 10 + shi;
console.log("逆序输出为:", newNum);
}
else {
console.log("这是一个1位数");
console.log("数字为:", num);
console.log("个位", num);
console.log("逆序输出为:", num);
}