【发布时间】:2018-11-19 16:26:44
【问题描述】:
如何让这段代码打印数组中的最大值?
示例 (view detailled screenshot):
- 玩家 1 得分 = 1
- 玩家 2 得分 = 2
-
玩家 3 得分 = 1
玩家 2 是赢家。
玩家 1 得分 = 1
- 玩家 2 得分 = 3
-
玩家 3 得分 = 3
玩家 2 是赢家。
玩家 3 是赢家。 玩家 1 得分 = 1
- 玩家 2 得分 = 1
- 玩家 3 得分 = 1
玩家 1 是赢家。
玩家 2 是赢家。
玩家 3 是赢家。`
到目前为止,这是我的代码尝试:
/**
* [algorithm description here]
* @param players
* @param cards
*/
public static void playGame(int players, int cards) {
if (players * cards > 52) {
System.out.println("Not enough cards for that many players.");
return;
}
boolean[] deck = new boolean[52];
int[] playerScore = new int[players];
for (int i = 0; i < players; i++) {
System.out.println("Player " + (i + 1));
int[] hand = Cards.dealHandFromDeck(cards, deck);
Cards.printHand(hand);
System.out.println("Score = " + Cards.pointValue(hand));
System.out.println();
playerScore[i] = Cards.pointValue(hand);
}
//go through playerScore array twice, first to find the highest score, then who has that score
}
【问题讨论】:
-
是什么阻止您在网上搜索以找到找到数组最大值的解决方案?
-
这是重复的,因为没有人帮助我¿?
-
没有什么能阻止我,我需要帮助才能打印数组的多个获胜者,而不仅仅是一个
-
是的,我写了那个评论聪明的家伙。这是我唯一需要的 cse 课程,我没有教科书,所以我在网上寻求帮助。 chegg 上的某个人帮助了我足够多的东西,无论如何我都可以弄清楚其余部分,代码在这篇文章的唯一答案下方作为评论,以防其他人需要帮助。不用感谢这个人^