zhyyyq
2019-09-14 15:17
import java.util.ArrayList;
import java.util.Random;
public class Pokegame{
ArrayList<Poke> cards = new ArrayList<Poke>();
public void init(){
for(int i = 1;i<=13;i++){
for(int j =1;j<=4;j++){
cards.add(new Poke(i,j));
}
}
}
public void flushCards(){
Random random = new Random();
for(int i =0;i<100;i++){
Poke a = cards.get(random.nextInt(52));
cards.remove(a);
cards.add(a);
}
}
public void show(){
for (Poke poke : cards) {
System.out.println(poke);
}
}
public static void main(String[] args) {
Pokegame game =new Pokegame();
game.init();
game.flushCards();
game.show();
}
}
Collections.shuffle(list);不是更简洁一点吗?
不秀,利用set的无序性就可以很简单的做到打乱了
感觉我这个洗牌很秀
Java入门第三季
409792 学习 · 4340 问题
相似问题