using System;
class Test1
{
 static void PrintArr(int ArrLength)
 {
   int[] arr=new int[ArrLength];
   for(int i=0;i<arr.Length;i++)
   arr[i]=i;
   Console.WriteLine("Print Array's alue");
   for(int i=0;i<arr.Length;i++)
   Console.WriteLine("arr[{0}]={1}",i,arr[i]); 
}
 static void Main()
  {
    int i=1;
    while(i>0)
    {
     Console.Write("Plesase enter the arrey's Length:");
     i=Int32.Parse(Console.ReadLine());
     PrintArr(i);
    }
  }
}for循环在这里为什么要写2次?

解决方案 »

  1.   

    不知道
    LZ知道乘法口诀的算法
    一个是用foreach
    一个是两个for循环
      

  2.   

    对于这个问题
    前面的一个for是给数组arr赋值
    后面是遍历数组中的值将值取出来
    就这样的
      

  3.   

    LZ
    结贴吧!
    o(∩_∩)o...
    还有那里不懂
      

  4.   

      for(int i=0;i <arr.Length;i++) 
      arr[i]=i; 
      Console.WriteLine("Print Array's alue"); //循环输出array's value
      for(int i=0;i <arr.Length;i++) 
      Console.WriteLine("arr[{0}]={1}",i,arr[i]); //循环输出 arr[i]=i;  未有效利用变量,写程序的人有问题。using System;
    class Test1
    {
        static void PrintArr(int ArrLength)
        {
            int[] arr = new int[ArrLength];
            //for (int i = 0; i < arr.Length; i++)
            
                
            Console.WriteLine("Print Array's alue");
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = i;
                Console.WriteLine("arr[{0}]={1}", i, arr[i]);
            }
            
        }
        static void Main()
        {
            int i = 1;
            while (i > 0)
            {
                Console.Write("Plesase enter the arrey's Length:");
                i = Int32.Parse(Console.ReadLine());
                PrintArr(i);
            }
        }
    }
      i=Int32.Parse(Console.ReadLine()); //让是输入的字符转化为整型  你写的程序是先输入一个数组长度,然后输出 arr[0]~arr[i-1]的值。
      

  5.   

      for(int i=0;i <arr.Length;i++) 
      arr[i]=i; //循环向数组输入数据.  for(int i=0;i <arr.Length;i++) 
      Console.WriteLine("arr[{0}]={1}",i,arr[i]); //循环将数据输出到屏幕.
      

  6.   

    楼主,那个程序相当于下面的程序。using System; 
    class Test1 

    static void PrintArr(int ArrLength) 

      int[] arr=new int[ArrLength]; 
      for(int i=0;i <arr.Length;i++) 
      {
        arr[i]=i; 
      }//这里是为数组arr赋值
      Console.WriteLine("Print Array's alue"); 
      for(int i=0;i <arr.Length;i++) 
      {
        Console.WriteLine("arr[{0}]={1}",i,arr[i]); 
      }//这里是循环打印数组中的每个值
    } 希望我的回答能帮上你忙。
    static void Main() 
      { 
        int i=1; 
        while(i>0) 
        { 
        Console.Write("Plesase enter the arrey's Length:"); 
        i=Int32.Parse(Console.ReadLine()); 
        PrintArr(i); 
        } 
      } 
    }