Exemplo n.º 1
0
        private static void LoadArray(ref double[] array)
        {
            int?size = Reading.ReadInt("Vložte velikost pole");

            if (size != null)
            {
                if (size < 1)
                {
                    Console.WriteLine("Zadal jsi nekladne cislo pro velikost pole");
                    return;
                }
                array = new double[(int)size];
                for (int i = 0; i < size; i++)
                {
                    double?value = Reading.ReadDouble($"Array[{i}]");
                    if (value != null)
                    {
                        array[i] = (double)value;
                    }
                    else
                    {
                        Console.WriteLine("Nezadal jsi cislo");
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine("Nezadal jsi cislo");
                return;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string name   = Reading.ReadString("Your name");
            int    age    = Reading.ReadInt("Your age");
            double points = Reading.ReadDouble("Points");
            char   grade  = Reading.ReadChar("Grade");

            Console.WriteLine('\n' + name + '\n' + age + '\n' + points + '\n' + grade);
        }
Exemplo n.º 3
0
        private static void FindLastValue(double[] array)
        {
            double?number = Reading.ReadDouble("Zadej hledane cislo");

            if (number != null)
            {
                for (int i = array.Length - 1; i >= 0; i--)
                {
                    if (array[i] == (double)number)
                    {
                        Console.WriteLine($"Posledni vyskyt cisla {number} se vyskytuje na indexu {i}");
                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void EnterNewDoubleToConsole(ref double[] fieldOfDoubles, ref int position)
        {
            var firstInput = Reading.ReadDouble("Please enter new double");
            var length     = fieldOfDoubles.Length;

            if (length == position)
            {
                var temp = new double[length + 1];
                for (var i = 0; i < length; i++)
                {
                    temp[i] = fieldOfDoubles[i];
                }

                fieldOfDoubles = temp;
            }

            fieldOfDoubles[position++] = firstInput;
        }
Exemplo n.º 5
0
        private void FindLastOccurenceOfNumberAndPrintToConsole(double[] fieldOfDoubles)
        {
            if (fieldOfDoubles.Length == 0)
            {
                WriteLineColorRed("Array is empty!");
                return;
            }

            var input = Reading.ReadDouble("Please enter double you want to find");

            for (int i = fieldOfDoubles.Length - 1; i > 0; i--)
            {
                if (fieldOfDoubles[i].Equals(input))
                {
                    Console.WriteLine($"Found last occurence of <{input}> at index <{i}>.");
                    return;
                }
            }

            WriteLineColorRed($"Number <{input}> was not found in array!");
        }