【java】彩票中奖码生成器:java.util.Random里的方法public int nextInt(int bound)

 package 彩票中奖码生成器;

 import java.util.Random;

 public class TestRandom {
public static void main(String[] args) {
Random random=new Random();
int[] numbers=new int[6];
int index=0;
while(index<numbers.length){
int num=random.nextInt(50);
if(!isContains(numbers,num))
numbers[index++]=num;
}
java.util.Arrays.sort(numbers);
for(int i:numbers){
System.out.print(i+",");
}
}
public static boolean isContains(int[] tmp,int num){
if(num==0)
return true;
for(int i=0;i<tmp.length;i++){
if(tmp[i]==num)
return true;
}
return false;
}
}
上一篇:维吉尼亚密码java完整版


下一篇:Path Sum II 解答