public class Test {
public static void main(String
[] args
) {
System
.out
.println(generateRandom(1));
System
.out
.println(generateRandom(2));
System
.out
.println(generateRandom(3));
System
.out
.println(generateRandom(4));
System
.out
.println(generateRandom(5));
System
.out
.println(generateRandom(6));
System
.out
.println(generateRandom(7));
System
.out
.println(generateRandom(8));
System
.out
.println(generateRandom(9));
System
.out
.println(generateRandom(10));
}
private static String
generateRandom(int digitNumber
) {
if (digitNumber
== 0) {
return "";
}
String randomStr
= String
.valueOf((int) ((Math
.random() * 9 + 1) * (Math
.pow(10, digitNumber
- 1))));
return randomStr
;
}
}
运行结果:
1
88
258
7450
11353
535570
7471218
59991806
236920083
2147483647
Process finished with exit code 0
转载请注明原文地址:https://tech.qufami.com/read-7317.html