Написать два метода - C#
Формулировка задачи:
Считать массив с экрана. Написать два метода: первый - возвращает числа больше 0; второй - возвращает числа меньше 0.
Написал код, но при его прогонке выдает System.Int32[]. После чего программа завершается.
Укажите на мои ошибки при написании кода.
Листинг программы
- class Program
- {
- public static string ARRAY_LENGTH_MSG = "Введите количество элементов";
- public static string ARRAY_ENTER_ELEMENTS_MSG = "Введите элементы";
- public static string POSITIVE_VALUES_MSG = "Положительные значения из массива:";
- public static string NEGATIVE_VALUES_MSG = "Отрицательные значения из массива:";
- public static string UNSIGNED_VALUE_MSG = "Значение без знака из массива:";
- static void Main(string[] args)
- {
- int[] array = new int[0];
- Console.WriteLine(ArrayOfSeedsValues());
- ValuesGreaterThan0(array);
- OfValuesThan0(array);
- UnsignedValue(array);
- Console.ReadLine();
- }
- public static int[] ArrayOfSeedsValues()
- {
- int arrayLength = ArrayLength();
- int[] array = new int[arrayLength];
- foreach (int i in array)
- {
- Console.WriteLine(ARRAY_ENTER_ELEMENTS_MSG, i + 1);
- array[i] = Convert.ToInt32(Console.ReadLine());
- }
- return array;
- }
- public static int ArrayLength()
- {
- Console.WriteLine(ARRAY_LENGTH_MSG);
- int lengthArray = Convert.ToInt32(Console.ReadLine());
- return lengthArray;
- }
- public static void ValuesGreaterThan0(int[] array)
- {
- var posNums = from n in array
- where n > 0
- select n;
- foreach (int x in posNums)
- {
- Console.Write(POSITIVE_VALUES_MSG + x);
- }
- }
- public static void OfValuesThan0(int[] array)
- {
- var negNums = from n in array
- where n < 0
- select n;
- foreach (int y in negNums)
- {
- Console.Write(NEGATIVE_VALUES_MSG + y);
- }
- }
- public static void UnsignedValue(int[] array)
- {
- var unsNums = from n in array
- where n == 0
- select n;
- foreach (int z in unsNums)
- {
- Console.Write(UNSIGNED_VALUE_MSG + z);
- }
- }
- }
- }
Решение задачи: «Написать два метода»
textual
Листинг программы
- static void Main(string[] args)
- {
- int arrayLength = ArrayLength();
- int[] array = new int[arrayLength];
- for (int i = 0; i < arrayLength; ++i)
- {
- Console.WriteLine(ARRAY_ENTER_ELEMENTS_MSG, i);
- array[i] = Convert.ToInt32(Console.ReadLine());
- }
- ValuesGreaterThan0(array);
- OfValuesThan0(array);
- UnsignedValue(array);
- Console.ReadLine();
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д