1 package com.wh.array; 2 3 public class Lottery { 4 5 public static void main(String[] args) { 6 int[] num=new int[11]; 7 //11个球 8 for (int i = 0; i < num.length; i++) { 9 num[i]=i+1; 10 } 11 12 //打乱排序 13 for (int i = 0; i < num.length; i++) { 14 int ran=(int)(Math.random()*11); 15 int temp=num[i]; 16 num[i]=num[ran]; 17 num[ran]=temp; 18 } 19 20 //输出前5个数 21 for (int i = 0; i < 5; i++) { 22 System.out.println(num[i]); 23 } 24 } 25 }