将数组中的元素排序,帮忙看看哪里有问题。
namespace Demo01
{
class Program
{
static void Main(string[]args){
int[] arr = new int[10] { 10, 21, 13, 4, 53, 62, 7, 8, 9, 17 };
int temp;
for (int i = 0; i <= 8; i++)
{
for (int j = 0; j <= 8 - i; j++)
{
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
foreach (int num in arr)
{
Console.Write(num + " ");
}
}
}
}
咋了?测试没问题吖