作者在 2008-06-15 11:36:25 发布以下内容
下面代码可以产生5位随机数,如何将它转换为以下形式的随机数的数组。还请高手帮忙,请给出修改的全部代码!
产生以下:然后显示0到8这八个数字在一个3*3的格子,让每个数字随机如下图所示:
+===+===+===+
+ 0 + 5 + 8 +
+ 7 + 4 + 3 +
+ 2 + 6 + 1 +
+===+===+===+
+===+===+===+
+ 0 + 5 + 8 +
+ 7 + 4 + 3 +
+ 2 + 6 + 1 +
+===+===+===+
下面是产生5个数的随机数,请高手帮忙修改:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
public static void Main(string[] args)
{
Random r = new Random();
int[] number = new int[5];
for (int i = 0; i < 5; i++)
{
{
class Program
{
public static void Main(string[] args)
{
Random r = new Random();
int[] number = new int[5];
for (int i = 0; i < 5; i++)
{
number[i] = r.Next(0, 6);
for (int j = 0; j < i; j++)
{
if (number[i] == number[j])
{
number[i] = r.Next(0, 6);
j = -1;
}
}
for (int j = 0; j < i; j++)
{
if (number[i] == number[j])
{
number[i] = r.Next(0, 6);
j = -1;
}
}
}
for (int j = 0; j < 5; j++)
{
Console.Write("{0} ", number[j]);
}
string sss = Console.ReadLine();
}
}
}
{
Console.Write("{0} ", number[j]);
}
string sss = Console.ReadLine();
}
}
}