• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
14软三2014330319佘迈
博客园    首页    新随笔    联系   管理    订阅  订阅

java第六次作业(老师讲过后)

import java.util.*;

public class Draw {
private ArrayList list;
public Draw() {
list= new ArrayList();
}
public void deal(int num) {
//向容器中添加奖券(使用循环)

		for (int j = 0; j<= num ; j++) {
			 list.add(j);
		
	}
	//打乱顺序
	Collections.shuffle( list);
}
public void drawLottery(int n){
  Random ra = new Random();
	
  for(int i=0;i<n;i++){
  int index =ra.nextInt(list.size());
  System.out.print(list.get(index)+"\t");
  list.remove(index);
  }
  System.out.println();
  }
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Draw c = new Draw();
	
	c.deal(100);
	System.out.println("————————一等奖————————");
	c.drawLottery(2);
	System.out.println("————————二等奖————————");
	c.drawLottery(5);
	System.out.println("————————三等奖————————");
	c.drawLottery(10);
}

}

posted @ 2016-05-16 18:35  小麦呀  阅读(108)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3