你这样取随机数是没有用的
最好还是用一个向量来保存所有的牌,然后取一张删一张,就不会有重复的了
----------------解决方案--------------------------------------------------------
你这样取随机数是没有用的
最好还是用一个向量来保存所有的牌,然后取一张删一张,就不会有重复的了
那你怎么保证你以前取过的下标没有重复的呢?
对啊,能不能跟我解释一下向量是什么意思啊
[CODE]/*
* SendCard.java
*
* Created on 2006年12月1日, 上午9:34
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author lbf
*/
import java.util.*;
public class SendCard {
private Vector<Card> v;
/** Creates a new instance of SendCard */
public SendCard() {
initOther();
}
private void initOther(){
v=new Vector<Card>();
for(int i=1;i<=13;i++){
v.add(new Card('A',i));
v.add(new Card('B',i));
v.add(new Card('C',i));
v.add(new Card('D',i));
}
}
public void display(){
int total=0;
while(v.size()!=0){
total++;
System.out.print(v.remove((int)(Math.random()*v.size()))+"\t");
if(total%13==0)
System.out.println();
}
}
public static void main(String[] args) {
SendCard sc=new SendCard();
sc.display();
}
}
class Card{
private int num;
private char name;
public Card(char name,int num){
this.num=num;
this.name=name;
}
public String toString(){
return ""+name+":"+num;
}
}[/CODE]
你看看吧