2018-12-19 倒序输出负数变0

2018-12-19  本文已影响0人  f387b2061819
            int[] array = { 1, 3, -1, 5, -2 };
            int[] nums = new int [array.Length ];
            int j=-1;

              for (int i = array.Length - 1; i >=0; i--)
            {
                  j++;
               if  (array [ j] > 0)
                {
                   nums [j]=array [i];
                }else 
               {
                   nums [j]=0;
               }
            for (int k = 0; k < nums.Length; k++)
            {
                Console.Write("{0},", nums[k]);
            }
            for (int l = 0; l < nums.Length; l++)
            {
                Console.Write("{0},", array [l]);
            }


            Console.ReadKey();
上一篇 下一篇

猜你喜欢

热点阅读