zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    mongodb 简单的更新语句
    centos 安装ffmpeg 及h264编码打包
    mongodb $where查询
    javascript 上传进度条
    javascript 仿豆瓣读书笔记
    js监听浏览器剪贴板
    ffmpeg相关操作
    ffmpeg未整理好,有时间整理下
    fffmpeg 提取pcm
    ffmpeg转MP4 moov头在前命令
  • 原文地址:https://www.cnblogs.com/dbda/p/11407330.html
Copyright © 2011-2022 走看看