1 package com.fqs.demo; 2 3 import java.util.Random; 4 5 6 public class JiWei { 7 public static void main(String[] args) { 8 //随机数给范围;求随机数的范围位数 9 Random sj=new Random(); 10 int sjnumber=sj.nextInt(10000)+1; 11 System.out.println("sjnumber:"+sjnumber); 12 int wei=0;//初始值是0 13 for(int temp=sjnumber;temp!=0;temp/=10) { 14 //每次都除以10,当等于0结束循环 15 wei++;//位数 计数 16 } 17 System.out.println("wei:"+wei); 18 } 19 20 }
标签:10,int,wei,sjnumber,位数,随机数,十进制 From: https://www.cnblogs.com/haha1988/p/17084247.html