java - 我将如何在Java中调用数组参数?

public void createDeck() {
    k=0;
    cards=new Card[52];

    for (i=0;i<4;i++) {
        for (j=0;j<13;j++){
            cards[k]=new Card(i,j);
            k++;                
        }
    }
}

public void shuffleDeck(int m){
    Random random = new Random(); 
    Card cardTemp;
    for(i=0;i<m;i++){
        k=random.nextInt(52);
        cardTemp=cards[i%52];
        cards[i%52]=cards[(i+k)%52];
        cards[(i+k)%52]=cardTemp;
    }                   
}


你好。我要带走的i和j

cards[k]=new Card(i,j);


因为我想通过选择i和j来显示西装的等级:

    public Card(int suit,int rank){
        this.rank=rank;
        this.suit=suit;
    }

  private final static String[] suits = { "Hearts", "Spades", "Diamonds", "Clubs" };

   private final static String[] ranks  = { "Ace", "2", "3", "4", "5", "6",
       "7", "8", "9", "10", "Jack", "Queen", "King" };


在另一堂课中

deck=new Deck();
deck.createDeck();
deck.shuffleDeck(111);


我应该使用另一个数组吗?我真的很困惑。我想给屏幕,例如改组后的ace心。

最佳答案

目前尚不清楚您在问什么,但我可以猜到,您想要的是从混洗的纸牌中抽出一张卡片时,您会看到它的等级和西装。对?

那么答案是向Card类添加2个方法:

public int getSuit()
{
   return suit;
}

public int getRank()
{
   return rank;
}


然后,当您抓牌时:

Card c = cards[k];
int cSuit = c.getSuit();
int cRank = c.getRank();