Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 05. Word Filter
- Read an array of strings and take only words, whose length is even. Print each word on a new line.
- Examples
- Input Output
- kiwi orange banana apple kiwi
- orange
- banana
- pizza cake pasta chips cake
- • Read an array of strings
- • Filter those whose length is even
- • Print each word on a new line
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace InboxManager
- {
- class Program
- {
- static void Main(string[] args)
- {
- var words = Console.ReadLine().Split().Where(x => x.Length % 2 == 0);
- foreach (var word in words)
- {
- // var counter = 0; //Втори вариант на решение.
- // foreach (var item in word)
- // {
- // counter++;
- // }
- // if (counter % 2 == 0)
- // {
- Console.WriteLine(word);
- // }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment