标签:package print stat sort ati port bre 随机 rgs
package java2; import java.util.Arrays; import java.util.Random; public class lottery_ticket { public static void main(String[] args) { int s = 35; int z = 7; System.out.println(Arrays.toString(ticket(s,z))); } static int[] ticket(int a,int b) { Random random = new Random(); int[] x = new int[b]; //定义一个长度为b的数组 for(int i=0;i<x.length;i++) { x[i] = random.nextInt(a)+1; //随机生成大于等于1,小于等于a的整数,进行赋值 for(int j=0;j<i;j++) { //去重 if(x[i] == x[j]) { i--; break; } } } Arrays.sort(x); //排序 return x; } }
标签:package print stat sort ati port bre 随机 rgs
原文地址:https://www.cnblogs.com/wangsihui/p/11876985.html