下文笔者讲述使用java代码生成三位数的随机数的方法分享,如下所示:
生成三位数的随机数
实现思路:
根据Math.random生成一个0~1的数,然后进行相应的数学运算,即可得到一个三位数
例:生成三位数的随机数
package com.java265.other;
public class Test11 {
/**
* java265.com 示例演示
*/
public static void main(String[] args) throws Exception {
int i = (int) (Math.random() * 900 + 100);
String str = Integer.toString(i);
System.out.println(str);
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


