我已经为“反转数组并且反转后不显示重复元素”编写了这个程序,但它只打印到倒数第二个元素:
int[] a = new int[] { 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 };
for (int i = 0; i < a.Length / 2; i++)
{
int tmp = a[i];//Getting First/current element
a[i] = a[a.Length - i - 1];//Getting last Element and assigning to first/current
a[a.Length - i - 1] = tmp;
}
int j=0;
for(int i=0;i< a.Length;i++)
{
j=i+1;
if(j < a.Length)
{
if (a[i] != a[j])
Console.WriteLine(a[i]);
}
j++;
}
我究竟做错了什么?