using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8};
int temp;
for (int i = 0; i < numbers.Length / 2; i++)// 数组的前一半元素跟后一半元素调换位置
{
// numbers[i]和 numbers[numbers.Length - i - 1]调换位置
temp = numbers[i];
numbers[i] = numbers[numbers.Length - i - 1];
numbers[numbers.Length - i - 1] = temp;
}
for(int i = 0; i < numbers.Length; i++)
{
Console.Write(numbers[i] + "\t");
}
Console.ReadKey();
}
}
}
数组元素倒序
最新推荐文章于 2024-08-05 15:45:51 发布