解释下代码的含义int[] numbers = new int[] { 6,4,3,2,9,1,7,8,5 };List even = new List();foreach (int number in numbers){if (number % 2 == 0){even.Add(number);}}even.Sort();even.Reverse();
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/24 21:02:58
解释下代码的含义int[] numbers = new int[] { 6,4,3,2,9,1,7,8,5 };List even = new List();foreach (int number in numbers){if (number % 2 == 0){even.Add(number);}}even.Sort();even.Reverse();
解释下代码的含义
int[] numbers = new int[] { 6,4,3,2,9,1,7,8,5 };
List even = new List();
foreach (int number in numbers)
{
if (number % 2 == 0)
{
even.Add(number);
}
}
even.Sort();
even.Reverse();
解释下代码的含义int[] numbers = new int[] { 6,4,3,2,9,1,7,8,5 };List even = new List();foreach (int number in numbers){if (number % 2 == 0){even.Add(number);}}even.Sort();even.Reverse();
int[] numbers = new int[] { 6,4,3,2,9,1,7,8,5 };
//定义 int数组
List even = new List();
//定义list对象even,其中放的类型为int
foreach (int number in numbers)
//循环 (循环类型 循环变量 循环数组)
{
if (number % 2 == 0)
//如果循环变量被2整除
{
even.Add(number);
//就添加到even这个list中
}
}
even.Sort();
//even排序,默认按自然排序
even.Reverse();
//even反转,就是排序最大的反而是最小的了.
如果打印even,会看到
8,6,4,2