# Odd/Even number split * 建立兩個包含整數數據類型的列表,一個用於偶數,一個用於奇數 * 迴圈從 0 到 20 * 如果數字是偶數,加入到偶數列表 * 如果數字是奇數,加入到奇數列表 * 列印偶數列表 * 列印奇數列表 ``` using System; using System.Collections.Generic; class Program { static void Main() { // 建立兩個列表:一個用於偶數,一個用於奇數 List<int> evenList = new List<int>(); List<int> oddList = new List<int>(); // 迴圈從 0 到 20 for (int i = 0; i <= 20; i++) { // 如果數字是偶數,加入到偶數列表 if (i % 2 == 0) { evenList.Add(i); } // 如果數字是奇數,加入到奇數列表 else { oddList.Add(i); } } // 列印偶數列表 Console.WriteLine("偶數列表: " + string.Join(", ", evenList)); // 列印奇數列表 Console.WriteLine("奇數列表: " + string.Join(", ", oddList)); } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up