这个简单,两个循环就行了
- string s = " 2 7 8 3 22 9 5 11";
- string[] ar = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < ar.Length; i++)
- {
- if (int.Parse(ar[i]) % 2 != 0)
- Console.Write(ar[i] + " ");
- }
- for (int i = 0; i < ar.Length; i++)
- {
- if (int.Parse(ar[i]) % 2 == 0)
- Console.Write(ar[i] + " ");
- }
复制代码 |