Unity3D开发-C#语言进阶篇(一维数组应用详解)

class Program
    {
        static void Main(string[] args)
        {Console.WriteLine("-----------第一题------------");
            chongfu://定义重复格式;
            Console.WriteLine("请输入1-10的整数");
            int L = Convert.ToInt32(Console.ReadLine());
            if (L > 0 && L <= 10)
            {
                int[][] arr1 = new int[L][];//定义二维数组;
                for (int i = 0; i < arr1.Length; i++)
                {
                    arr1[i] = new int[i + 1];//二维数组里的一维数组重新new一遍;
                    for (int j = 0; j < arr1[i].Length; j++)//注意二维数组里一维数组的长度;
                    {
                        arr1[i][j] = 2 * j + 1;//按要求赋值;
                    }
                }



                foreach (int[] arr_1 in arr1)//遍历数组;
                {
                    foreach (int arr_11 in arr_1)
                    {
                        Console.Write(arr_11 + " ");
                    }
                    Console.WriteLine();
                }
            }
            else
            {
                goto chongfu;//goto语句;
            }



            Console.WriteLine("-----------第二题------------");
            chongfu1:
            Console.WriteLine("请输入人数:");
            int L2 = Convert.ToInt32(Console.ReadLine());
            int[] arr2 =new int[L2];
            for (int i=0;i

你可能感兴趣的:(Unity3D开发-C#语言进阶篇(一维数组应用详解))