`

生成8位随机数

 
阅读更多

public static void main(String[] args) {

 

String str = "";

 

str += (int)(Math.random()*9+1);

 

for(int i = 0; i < 7; i++){//更改这里 可以控制生成数字的位数

 

str += (int)(Math.random()*10);

 

}

 

int num = Integer.parseInt(str);

 

System.out.println(num);

}

http://blog.sohu.com/s/MTAyMjIxNjYy/300349452.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics