java第六次作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java第六次作业相关的知识,希望对你有一定的参考价值。
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.*;
public class choujiang {
private ArrayList<Integer> cards;
public void deal(int num){
if (cards==null){
cards=new ArrayList<Integer>();
for(num=1;num<=100;num++){
cards.add(num);
}
}
Collections.shuffle(cards);
}
public void draw(){
Random ra=new Random();
int s =ra.nextInt(cards.size());
System.out.println("一等奖:"+ cards.get(s));
cards.remove(cards.get(s));
Collections.shuffle(cards);
for(int i=0;i<2;i++){
int stwo=ra.nextInt(cards.size());
System.out.println("二等奖:"+ cards.get(stwo));
cards.remove(cards.get(stwo));
}
Collections.shuffle(cards);
for(int j =0;j<3;j++){
int sthree =ra.nextInt(cards.size());
System.out.println("三等奖:"+cards.get(sthree));
cards.remove(cards.get(sthree));
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
choujiang c = new choujiang();
c.deal(0);
c.draw();
}
}
以上是关于java第六次作业的主要内容,如果未能解决你的问题,请参考以下文章