package com.itheima;
import java.util.Random;
public class Random_Demo2 {
public static void main(String[] args) {
int count=0;
long start=System.currentTimeMillis();
while (true) {
int i1 = new Random().nextInt(1000);
int i2 = new Random().nextInt(1000);
System.out.println("第"+(count+1)+"次"+" "+"随机数1为"+i1+" "+"随机数2为"+i2);
if (i1==i2){
System.out.println("随机数相等");
long end=System.currentTimeMillis();
System.out.println("用了"+(count+1)+"次");
System.out.println("用时"+(end-start)/1000+"秒");
break;
}else{
System.out.println("不相等,继续随机");
System.out.println();
count++;
}
}
}
}
2个随机数
最新推荐文章于 2022-08-24 09:12:46 发布