Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp10
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Посчитать кол-во слов, чисел и знаков препинания в предложении
- string str = "Пока наши корабли в количестве 2 штук бороздят просторы Большого Театра, мы не в состоянии покорить 7 систему!";
- string[] words = str.Split(new char[] {' '});
- int DigitCounter = 0;
- int PunctuationCounter = 0;
- Console.WriteLine(str);
- Console.WriteLine("Так-так, щас посмотрим...");
- Console.ForegroundColor = ConsoleColor.Cyan;
- foreach (string word in words)
- {
- int number;
- bool IsNumber = Int32.TryParse(word, out number);
- if (IsNumber)
- {
- DigitCounter++;
- Console.WriteLine($"{word} является числом, класс!");
- }
- }
- for (int i = 0; i < str.Length; i++)
- if (Char.IsPunctuation(str[i]))
- PunctuationCounter++;
- Console.ResetColor();
- Console.WriteLine($"Всего чисел: {DigitCounter}\nВсего слов: {words.Length}\nВсего знаков препинания: {PunctuationCounter}");
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement