分享一下我的代碼
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();
????}
}
2019-11-18
Collections.shuffle(list);不是更簡潔一點(diǎn)嗎?
2019-11-06
不秀,利用set的無序性就可以很簡單的做到打亂了
2019-09-14
感覺我這個(gè)洗牌很秀