public class Test903 { public static void main(String[] args) { ArrayList arrayList=new ArrayList(); Scanner scanner=new Scanner(System.in); int f=scanner.nextInt(); while(arrayList.size()<74){ if (arrayList.size()<1){ arrayList.add(num(f)); } int j= num(f); //判断是否已经存在,不重复的关键 boolean b=arrayList.contains(j); if(b==false){ arrayList.add(j); //System.out.println(arrayList); } } //循环输出,可以自定义 for (int i = 0; i <arrayList.size() ; i++) { System.out.println(arrayList.get(i)); } } //生成一个随机数 public static int num(int f) { Random random=new Random(); //+1是为了过滤0,并包含f return random.nextInt(f)+1; } }