Advertisement
RMarK0

Untitled

Dec 26th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. namespace ConsoleApp10
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             // Посчитать кол-во слов, чисел и знаков препинания в предложении
  8.  
  9.             string str = "Пока наши корабли в количестве 2 штук бороздят просторы Большого Театра, мы не в состоянии покорить 7 систему!";
  10.             string[] words = str.Split(new char[] {' '});
  11.             int DigitCounter = 0;
  12.             int PunctuationCounter = 0;
  13.             Console.WriteLine(str);
  14.             Console.WriteLine("Так-так, щас посмотрим...");
  15.             Console.ForegroundColor = ConsoleColor.Cyan;
  16.             foreach (string word in words)
  17.             {
  18.                 int number;
  19.                 bool IsNumber = Int32.TryParse(word, out number);
  20.                 if (IsNumber)
  21.                 {
  22.                     DigitCounter++;
  23.                     Console.WriteLine($"{word} является числом, класс!");
  24.                 }
  25.             }
  26.             for (int i = 0; i < str.Length; i++)
  27.                 if (Char.IsPunctuation(str[i]))
  28.                     PunctuationCounter++;
  29.             Console.ResetColor();
  30.             Console.WriteLine($"Всего чисел: {DigitCounter}\nВсего слов: {words.Length}\nВсего знаков препинания: {PunctuationCounter}");
  31.             Console.Read();
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement