【发布时间】:2021-12-09 06:46:48
【问题描述】:
我想比较两个“骰子”数组,看看有多少种方法可以使用两个骰子创建 10 的总和,然后将“10 对”的数量添加到另一个变量中。
这是我目前所拥有的,我不确定如何启动 forEach 循环(或者这是否是我想要使用的):
{
//Store 10-pairs in a new variable
int tenPairs = 0;
// Need variables to define the dice - arrays starting at 1?
int[] die1 = Enumerable.Range(1, num1).ToArray();
int[] die2 = Enumerable.Range(1, num2).ToArray();
//Compare each item from die1 to each value from die2 to see if they
//add up to 10.
//return a string with the message: "There are X total ways to get the sum 10."
string resultMsg = "There are " + tenPairs +" total ways to make 10.";
return resultMsg ;
}
【问题讨论】: