zoukankan      html  css  js  c++  java
  • 判断输入数的位数和每位数的多少

    import java.util.Scanner;
    public class TestDemo {

    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);//键盘输入数字
    System.out.println("请输入一个数");
    int a = sc.nextInt();
    int temp=10;
    String str = String.valueOf(a); //将数字转换成字符串
    int b = str.length(); //判断该字符串长度,即数字位数
    System.out.println("该数字:"+b+"位,");
    while(b>0){
    int x = a%temp; //得到末尾数数字
    a = a/temp;
    System.out.print(x+",");
    b--;
    }
    }
    }
  • 相关阅读:
    Web基础 网页的血肉CSS
    18
    19
    20
    17
    16
    15
    13
    14
    12
  • 原文地址:https://www.cnblogs.com/GodZhe/p/4777430.html
Copyright © 2011-2022 走看看