看板 java 關於我們 聯絡資訊
int[] dealcard = new int[52]; int ij; int[] cards = new int[52]; cards={裡面有52個數字但沒有0} for(i=0;i<52;i++) { j=(int)(Math.random()*52); if(cards[j]==0) //這邊是判斷cards取亂數的那個空間 是否以機被取過 { j=(int)(Math.random()*52); } dealcard[i]=cards[j]; //把cards[j]的值傳到dealcard cards[j]=0;//然後把那個以傳送過的陣列的空格傳0進去 } 好怪...我是不是少了哪個判斷.. 因為不管怎麼取.. dealcard印出來都會有0... 可不可以告訴我 我錯在哪裡.. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.217.163.164
LPH66:因為你只重取了一次 如果重取又是0就會出事 11/23 22:52
swpoker:if(cards[j]==0) --> while(cards[j]==0) 11/23 22:58
gene07:原來如此...用continue也可以囉0.0 11/23 23:56
※ 編輯: gene07 來自: 61.217.163.164 (11/23 23:57)
slalala:用雜湊表 比較簡單XD 11/24 00:26
csihcs:我會考慮用List的get和remove搭配得到不重複的效果 11/24 01:08
csihcs:這樣可以省掉檢查的時間,但需要較多的空間,不過看到Array 11/24 01:10
csihcs:想來你應該就不會介意使用太多空間的問題了 11/24 01:12