我目前是刚学习java,因为在国外上学,讲解能力是在是只能用灾难来形容。所以来这里请求帮助。
目前已经学习了Scanner,radom,if类,while,do,for类。现在开始学习Array。但实在是不理解。也只能用以上的语句。其他的没学过不让用
这是问题,
如图所示,创建三个array,第三个array需要将前两个整合起来。对于这个我是实在不理解
这是第二问:
英文:Section2: In this section, you need to randomly shuffle the deck of cards created in section1 as
below:
Algorithm to shuffle the deck:
▪ Consider each card index i from 0 to 51
• Calculate a random index r between i and 51
• Exchange deck[i] with deck[r]
机器翻译:Section2:在本节中,您需要将section1中创建的牌组随机洗牌为
以下:
洗牌的算法:
▪ 考虑每张卡片索引 i 从 0 到 51
• 计算一个介于 i 和 51 之间的随机索引 r
• 交换 deck[i] 和 deck[r]
对于这个问题似乎是将卡牌随机排列。我看例子用了两个for 语句。将for语句嵌套在另一个里面。因此如果可以麻烦使用两个for来回答这个问题。
第三问是
英文:
Algorithm to play the game:
- Prompt the user to enter number of cards, which will represent the winning cards, and
store it in variable cardNum - The system randomly selects cardNum unique cards from the deck and store them in a
new array called winningCards - Create a counter variable called totalDrawnCards to hold the total number of drawn
cards and initialize it to 0 - The user randomly draws cards one a time and find whether the drawn card match any
of the winning cards or not. - If the drawn card matches any of the winning cards, mark that card as selected.
- Increase totalDrawnCards by one.
- Repeat steps 4 through 6 until all the winning cards are drawn.
机器翻译:
玩游戏的算法:
- 提示用户输入代表中奖牌的牌数,以及
将其存储在变量 cardNum 中 - 系统从牌组中随机选择cardNum唯一的牌,存入一个
名为 winningCards 的新数组 - 创建一个名为totalDrawnCards的计数器变量来保存抽取的总数
卡并将其初始化为0 - 用户每次随机抽一张牌,看抽到的牌是否匹配
中奖卡与否。 - 如果抽到的牌与任何获胜牌相匹配,则将该牌标记为已选中。
- 将 totalDrawnCards 增加一。
- 重复步骤 4 到 6,直到抽出所有中奖牌。
这是输出的举例: