public static void CalculateSummOfEven(int [,] array)
        {
            int summ = 0;
            var numberOfEvenElements = 0;

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    switch ((i + j) % 2)
                    {
                    case 0:
                        ConsoleHelper.WriteText($"{i} {j}");
                        numberOfEvenElements++;
                        summ = summ + array[i, j];
                        break;

                    case 1:
                        break;

                    default:
                        throw new Exception("Unexpected exception.");
                    }
                }
            }
            ConsoleHelper.WriteText($"Number of even elements is:{numberOfEvenElements}.\nSumm is: {summ}");
        }
Example #2
0
        public static void Build(int count)
        {
            char   star = '*';
            string text = string.Empty;

            for (int i = 0; i < count; i++)
            {
                text = text + star;
                ConsoleHelper.WriteText(text);
            }
        }
        private static void ChangeStyle(ref Styles currentStyle)
        {
            int theChoise = ConsoleHelper.ReadValue($"Choose one of allowed styles:\n1: {Styles.bold.ToString()}\n" +
                                                    $"2: {Styles.italic.ToString()}\n3: {Styles.underline.ToString()}\n4: If style suits you\n");

            if (theChoise > 4
                )
            {
                theChoise = ConsoleHelper.ReadValue($"Variant {theChoise} does not exist. Enter existing variant.");
            }
            switch (theChoise)
            {
            case 1:
                currentStyle = currentStyle ^ Styles.bold;
                if (currentStyle == 0)
                {
                    currentStyle = (Styles.none);
                }
                RemoveNoneIfNeeded(ref currentStyle);
                ConsoleHelper.WriteText($"Current style is {currentStyle.ToString()}\n");
                ChangeStyle(ref currentStyle);
                break;

            case 2:
                currentStyle = currentStyle ^ Styles.italic;
                if (currentStyle == 0)
                {
                    currentStyle = (Styles.none);
                }
                RemoveNoneIfNeeded(ref currentStyle);
                ConsoleHelper.WriteText($"Current style is {currentStyle.ToString()}\n");
                ChangeStyle(ref currentStyle);
                break;

            case 3:
                currentStyle = currentStyle ^ Styles.underline;
                if (currentStyle == 0)
                {
                    currentStyle = (Styles.none);
                }
                RemoveNoneIfNeeded(ref currentStyle);
                ConsoleHelper.WriteText($"Current style is {currentStyle.ToString()}\n");
                ChangeStyle(ref currentStyle);
                break;

            case 4:
                ConsoleHelper.WriteText($"Current style is {currentStyle.ToString()}\n");
                break;

            default:
                throw new Exception("Unexpected exception.");
            }
        }
        public static void FindMax(int [] array)
        {
            int max = array[0];

            foreach (int i in array)
            {
                if (i > max)
                {
                    max = i;
                }
            }
            ConsoleHelper.WriteText($"Max value is {max}");
        }
        public static void FindMin(int[] array)
        {
            int min = array[0];

            foreach (int i in array)
            {
                if (i < min)
                {
                    min = i;
                }
            }
            ConsoleHelper.WriteText($"Min value is {min}");
        }
        public static void CalculateNonNegativeSumm(int [] array)
        {
            int summ = 0;
            int min  = array[0];

            foreach (int i in array)
            {
                if (i > 0)
                {
                    summ = summ + i;
                }
            }
            ConsoleHelper.WriteText($"Summ of all positive values is: {summ}");
        }
        public static int [] GenerateOneDimensional()
        {
            Random rnd = new Random();
            int    a   = rnd.Next(1, 30);

            int[] newarray = new int[a];
            for (int i = 0; i < newarray.Length; i++)
            {
                newarray[i] = rnd.Next(-99, 99);
            }
            ConsoleHelper.WriteText($"New array is:");
            ConsoleHelper.WriteArray(newarray);
            return(newarray);
        }
        public static void FindAverageInSentence(string str)
        {
            string[] words           = SplitToWords(str);
            var      numberOfWords   = 0;
            var      numberOfSymbols = 0;

            foreach (string word in words)
            {
                numberOfWords++;
                numberOfSymbols += word.Length;
            }
            var average = numberOfSymbols / numberOfWords;

            ConsoleHelper.WriteText($"Number of words is: {numberOfWords}.\nAverage is: {average}");
        }
        public static void NumberOfLowerStartWods(string str)
        {
            string[] words              = SplitToWords(str);
            var      numberOfWords      = 0;
            var      numberOfLowerWords = 0;

            foreach (string word in words)
            {
                numberOfWords++;
                if (char.IsLower(word, 0))
                {
                    numberOfLowerWords++;
                }
            }
            ConsoleHelper.WriteText($"Number of words is: {numberOfWords}.\nStarts with lower: {numberOfLowerWords}");
        }
 public static void BubbleSort(int [] array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         for (int j = i + 1; j < array.Length; j++)
         {
             if (array[i] > array[j])
             {
                 int a = array[i];
                 array[i] = array[j];
                 array[j] = a;
             }
         }
     }
     ConsoleHelper.WriteText($"Sorted array is:");
     ConsoleHelper.WriteArray(array);
 }
        public static int [,] GenerateTwoDimensional()
        {
            Random rnd = new Random();
            int    a   = rnd.Next(1, 15);
            int    b   = rnd.Next(1, 15);

            int[,] newarray = new int[a, b];
            for (int i = 0; i < newarray.GetLength(0); i++)
            {
                for (int j = 0; j < newarray.GetLength(1); j++)
                {
                    newarray[i, j] = rnd.Next(1, 50);
                }
            }
            ConsoleHelper.WriteText($"New array is:");
            ConsoleHelper.WriteTwoDimensionalArray(newarray);
            return(newarray);
        }
        public static void ReplaceAllPositive(int [,,] array)
        {
            int numberOfReplaces = 0;

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    for (int n = 0; n < array.GetLength(2); n++)
                    {
                        if (array[i, j, n] > 0)
                        {
                            numberOfReplaces = numberOfReplaces + 1;
                            array[i, j, n]   = 0;
                        }
                    }
                }
            }
            ConsoleHelper.WriteText($"Array after replacing:");
            ConsoleHelper.WriteThreeDimensionalArray(array);
            ConsoleHelper.WriteText($"Replaced: {numberOfReplaces} values.");
        }
        public static int[, ,] GenerateThreeDimensional()
        {
            Random rnd = new Random();
            int    x   = rnd.Next(1, 10);
            int    y   = rnd.Next(1, 10);
            int    z   = rnd.Next(1, 10);

            int[, ,] newarray = new int[x, y, z];
            for (int i = 0; i < newarray.GetLength(0); i++)
            {
                for (int j = 0; j < newarray.GetLength(1); j++)
                {
                    for (int n = 0; n < newarray.GetLength(2); n++)
                    {
                        newarray[i, j, n] = rnd.Next(-10, 10);
                    }
                }
            }
            ConsoleHelper.WriteText($"New array is:");
            ConsoleHelper.WriteThreeDimensionalArray(newarray);
            return(newarray);
        }
        public static void DoubleMatches(string str1, string str2)
        {
            ConsoleHelper.WriteText($"вошло в метод:{str1} {str2}");
            var secondString = DeleteMatches(str2);

            ConsoleHelper.WriteText($"пришло после удаления задвоений: {secondString}");
            ConsoleHelper.PressAnyKey();
            StringBuilder doubledString = new StringBuilder();

            for (int i = 0; i < str1.Length; i++)
            {
                doubledString.Append(str1[i], 1);
                foreach (char symbol in secondString)
                {
                    if (str1[i].Equals(symbol))
                    {
                        doubledString.Append(str1[i], 1);
                    }
                }
            }
            ConsoleHelper.WriteText($"{doubledString.ToString()}");
        }
 public static void ShowWritingStyle()
 {
     ConsoleHelper.WriteText($"Current style is {currentStyle.ToString()}\n");
     currentStyle = currentStyle ^ Styles.none;
     ChangeStyle(ref currentStyle);
 }