From 3ce69948dc84ecf75cbabb8cdd7107580f1e9d4c Mon Sep 17 00:00:00 2001 From: Tabor Wondimu Date: Thu, 17 Feb 2022 15:20:20 -0800 Subject: [PATCH] Finished the TODOS --- ArraysAndLists/Program.cs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/ArraysAndLists/Program.cs b/ArraysAndLists/Program.cs index 9899476..1432ba5 100644 --- a/ArraysAndLists/Program.cs +++ b/ArraysAndLists/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace ArraysAndLists { @@ -9,11 +10,13 @@ static void Main(string[] args) //TODO: // Create an int Array and populate numbers 1-10 - + int[] vs = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; /* Create two Lists of type int. * Name one List "evens" * Name the other List "odds" */ + var odd = new List (); + var even = new List (); /* Using either a foreach or for loop, * nest an if statement to check to see @@ -21,12 +24,36 @@ static void Main(string[] args) * Then add those numbers to either the evens List * or the odds List */ - + for (int i = 0; i <= 20; i++) + { + if (i % 2 == 0) + { + even.Add(i); + } + else if (i % 2 > 0) + { + odd.Add(i); + + } + } + /* Now using foeach or for loops, * display each List of even and odd numbers * * Try to be creative in your display */ + Console.WriteLine("These are the odd numbers"); + foreach (int i in odd) + { + Console.WriteLine(i); + } + Console.WriteLine("These are the even numbers"); + foreach (int i in even) + { + Console.WriteLine(i); + } + + } } }