int[] nums = { 1, 20, 35, 8, -20, 230, 38 };
//去掉负数
List<int> list = new List<int>();
foreach (int num in nums)
{
if (num >= 0)
list.Add(num);
}
int[]arr=list.ToArray();
//降序排列
for (int i = 0; i <arr.Length-1; i++)
{
for (int j = i+1; j < arr.Length; j++)
{
if (arr[i] < arr[j])
arr[i] = arr[j] + (arr[j] = arr[i]) * 0;
}
}
//格式化输出
StringBuilder sb = new StringBuilder();
foreach (int num in arr)
{
sb.Append(string.Format("【{0}】", num));
}
Console.WriteLine(sb);
Console.ReadKey();
|
|