我在比较数组中的元素时遇到了一些问题。我正在创建一个扑克问题,似乎无法编写代码来判断两个元素是否相同。这是我比较元素中的内容的代码
public static boolean pairs() {
for (int i = currentCard; i < deck.length; i++) {
for (int j = currentCard ; j < deck.length; j++) {
if (deck[i] == deck[j])
return pairs == true;
}
}
return pairs;
}
这是构建数组的代码:
public CreateDeck() {
String[] faces = { "Ace", "Deuce", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
String[] suits = { "Hearts", "Diamonds", "Spades", "Clubs" };
deck = new Card[NUMBER_OF_CARDS];
currentCard = 0;
for (int count = 0; count < deck.length; count++)
deck[count] = new Card(faces[count % 13], suits[count / 13]);
}
任何帮助将不胜感激,我尝试了很多事情,现在只是随机尝试。谢谢!