10.9. Exercises: Control Flow and Collections

10.9.1. Array Practice

  1. Fork this replit Array Practice.

  2. Create and initialize an array with the following values in a single line:

    1, 1, 2, 3, 5, 8
    
  3. Loop through the array and print out each value.

  4. Modify the loop to only print the odd numbers from the array.

10.9.2. String Practice

  1. Fork this replit String Practice.

  2. For this exercise, create a string for the value:

    I would not, could not, in a box. I would not, could not with a fox.
    I will not eat them in a house. I will not eat them with a mouse.
    
  3. Use the Split method to divide the string at each space and store the individual words in an array. If you need to review the method syntax, look back at the string methods table.

  4. Print the array of words to verify that your code works. The syntax is:

    Console.WriteLine(string.Join(",", arrayName));
    
  5. Repeat steps 2 and 3, but change the delimiter to split the string into separate sentences.

10.9.3. List Practice

  1. Fork this replit List Practice.

  2. Write a static method to find the sum of all the even numbers in a List.

  3. Within Main, create a list with at least 10 integers and call your method on the list.

  4. Write a static method to print out each word in a list that has exactly 5 letters.

  5. Modify your code to prompt the user to enter the word length for the search.

Bonus Mission: Update your solution from the List Practice section to use the string from the String Practice section. Search “C# convert string to list” online to see how to split a string into the more flexible List collection.

10.9.4. Dictionary Practice

Fork this replit Dictionary Practice.

Make a program similar to GradebookDictionary that does the following:

  1. It takes in student names and ID numbers (as integers) instead of names and grades.

  2. The keys should be the IDs and the values should be the names.

  3. Modify the roster printing code accordingly.