【发布时间】:2015-10-20 22:14:27
【问题描述】:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiceGame
{
class Program
{
static void Main(string[] args)
{
Random randomnumber = new Random();
int[] Player = new int[5];
Player[0] = randomnumber.Next(1, 6);
Player[1] = randomnumber.Next(1, 6);
Player[2] = randomnumber.Next(1, 6);
Player[3] = randomnumber.Next(1, 6);
Player[4] = randomnumber.Next(1, 6);
Console.WriteLine("You rolled a " + Player[0] + " " + Player[1] + " " + Player[2] + " " + Player[3] + " " + Player[4]);
Console.WriteLine(" You have a " + however many are equal);
}
}
}
编辑:我需要将数组中的多个数字相互比较。它们是随机的 1-6,如果 2 彼此相等,我需要显示对。如果3相等则显示3个,如果4个4个5个,5个个
edit2:我唯一能找到的是这个,但它只将 Player[0] 与数组的其余部分进行比较
for (int i = 0; i < Player.Length; i++)
{
int count = 0;
for (int j = 0; j < Player.Length; j++)
{
if (Player[i] == Player[j])
count = count + 1;
}
Console.WriteLine("\t\n " + Player[i] + " occurs " + count);
Console.ReadKey();
【问题讨论】:
-
这里只有一个数组。你想和什么比较?
-
“如果 2 相等”是什么意思? (顺便说一句,在 Stack Overflow 上,使用完整的英语而不是文本语言通常会有所帮助。)
-
你试过什么?此外,请尝试使用完整的单词,这样可以更容易阅读问题,并且您可能看起来对帮助的人有些尊重。
-
与数组中的其他数字
-
@RyanVanDusen 请向我们展示您的尝试。也许这会更清楚地说明实际问题。
标签: c# arrays comparison