int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
List<int> oddList = new List<int>();
List<int> evenList = new List<int>();
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] % 2 == 0)
{
evenList.Add(numbers[i]);
}
else
{
oddList.Add(numbers[i]);
}
}
Console.WriteLine("奇数集合是");
foreach (int item in oddList)
{
Console.WriteLine(item);
}
Console.WriteLine("===================================");
Console.WriteLine("偶数集合是");
foreach (int item in evenList)
{
Console.WriteLine(item);
}
Console.ReadKey(); |