Java生成随机值

    科技2022-07-16  105

    Java 指定范围随机生成数值

    System.out.print("生成几组:"); int LotteryNum = new Scanner(System.in).nextInt(); //彩票 System.out.printf("您生成了%s注,需支付%s元,正在为您随机生成组:\n",LotteryNum,LotteryNum*2); Random rand = new Random(); //随机数 for (int j = 0; j < LotteryNum; j++) { int Lottery[]= new int[7]; //定义一个数组 for(int i=0; i<7; i++) //7个号码 { // System.out.println(rand.nextInt(36) + 1); //区间为[1,36] Lottery[i]=rand.nextInt(36) + 1; //存进数组里面 } Arrays.sort(Lottery); //从小到大排序 System.out.println("您的第 "+(j+1)+" 注为(已经为您从小到大排序了:):"+Arrays.toString(Lottery)); //一次打印数组里面全部的东西 }
    Processed: 0.008, SQL: 8