转成字符串 然后看长度就是几位数了

import java.util.Scanner;
/**
 *
 * @author Administrator
 */
public class shuzi {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        System.out.println("请输入数字:");
        int shu=input.nextInt();
        String s=String.valueOf(shu);
        //或使用:String s=Integer.toString(shu);
        int t=s.length();
        System.out.println("你输入的数的位数为:"+t);
        // TODO code application logic here
    }
}

results matching ""

    No results matching ""