从1-36中随机出6个不相等的数
package lianxi; import java.util.*; public class Suijishu { public static void main(String[] args) { int ary[]=new int[6]; for (int i = 0; i <6; i++) { Random r=new Random(); ary[i]=r.nextInt(36); //判断是否有元素等于0 if(ary[i]==0) { i--; continue; } //判断有没有重复 for (int j = 0; j < i; j++) { if(ary[j]==ary[i]) { i--; break; } } } //遍历集合 for (int t : ary) { System.out.print(" "+t); } } }