public class Test {
public static void main(String[] args) {
for(int i = 0;i < 10 ; i++){
//Math.random()的取值范围是[0,1)
//Math.random() * 9000的取值范围是[0,8999]
//Math.random() * 9000 + 1000的取值范围是[1000,9999]
int num = (int)(Math.random() * 9000 + 1000);
System.out.println(i+1 + "==>" +num);
}
}
}
import java.util.Random;
public class Test{
public static void main(String[] args) {
Random ran = new Random();
for(int i=0;i<10;i++){
int num = ran.nextInt(9000)+1000;
System.out.print(num+"\t");
}
}
}
import java.util.ArrayList;
public class test {
public static void main(String[] args) {
//生成随机数
ArrayListrandomNums = new ArrayList ();
for (int i = 0; i < 10; i++) {
randomNums.add((int)(Math.random() * 900 + 100));
}
//排序输出
for (int i = 0; i < 10; i++) {
Integer max = 0;
for (Integer num : randomNums) {
if (num > max) {
max = num;
}
}
System.out.println(max);
randomNums.remove(max);
}
}
}
public class MathRandom {
public static void main(String[] args){
for(int i = 0;i < 10;i++){
int randomnum = (int)(Math.random()*9000+1000);
System.out.println(randomnum);
}
}
}