import java.util.*; public class RandomNum { public static void main(String[] args) { int min=99999999; int max=-1; int randomNum=0; Scanner sc=new Scanner(System.in); int num=sc.nextInt(); Random random = new Random(); for(int i=0;i<100000;i++){ randomNum = random.nextInt(num);//给出来的是(0~(num-1))之间的随机数,因此想要获得的话需要加一!!! if(randomNum<min){ min=randomNum; } if(randomNum>max){ max=randomNum; } } System.out.println("min="+(min+1)+" "+"max"+(max+1)+" "+"随机数:"+randomNum); } }
时间: 2024-10-08 22:33:06