Venciity

[Jumpstart C#] Arrays 02-UpperLetter

Feb 17th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. /*  Напишете програма която приема като вход от потребителя текстов ред съдържащ думи разделени с интервал.
  2.     Нека програмата отпечата всички думи от въведения текст които започват с главна буква.
  3.     (Hint: използвайте методите Split на класа String и IsUpper на Char)
  4.     Примeр:
  5.     Вход: The wolf of Wall Street
  6.     Изход: The Wall Street   */
  7.  
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13.  
  14. namespace _02_UpperLetter
  15. {
  16.     class UpperLetter
  17.     {
  18.         static void Main()
  19.         {
  20.             Console.WriteLine("Write some text:");
  21.             Console.WriteLine();
  22.             string line = Console.ReadLine();
  23.             string [] words = line.Split(' ');
  24.  
  25.             Console.WriteLine();
  26.             Console.WriteLine("UpperLetters in text are: ");
  27.             Console.WriteLine();
  28.             foreach (var word in words)
  29.             {
  30.                if(char.IsUpper(word[0]))  // string се държи като масив. Елементите на string са чарове (char) можем да достъпим свсеки един char чрез индекс.
  31.                    Console.Write(word + " ");
  32.             }
  33.             Console.ReadLine();
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment