有一个1,2,3....49 的数组,通过控制台显示为7行7列的,并且里面的数据时随机的代码...
主要代碼:
static void Main(string[] args)
{
int a= 49;
int[] array = new int[49];
//將數字添加到array中
for(int i =0; i <array.Length; i++)
{
array[i]? = i +1;
}
//new一個隨機數
Random random = new Random();
//創建一個隨機數的下標
int index;
int temp;
for(int i=48; i>=0; i--)
{
index = random.Next(0,a);
temp = array[index];
array[index] = array[a-1];
array[a-1] = temp;
a--;
}
//排列成7行7列
for(int i =0,j=0; i<49; j++,i++)
{
Console.Write(array[i] + "\t");
if((j+1)%7 == 0)
{
Console.WriteLine("\t");
}
}
}???
轉載于:https://www.cnblogs.com/jasonjiang/archive/2010/06/24/1764381.html
總結
以上是生活随笔為你收集整理的有一个1,2,3....49 的数组,通过控制台显示为7行7列的,并且里面的数据时随机的代码...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WinPcap过滤串表达式的语法
- 下一篇: fatal error C1071: u