Hello, I’m working on this task:
Call a method GetNumbersFromConsole that reads a count value of int, and then reads count values from the console into an int array. Separate ‘Big’ and ‘Little’ integers into two separate arrays: Big if the integer is greater than 100; Little otherwise. Then output the values in the Big array on one line and the values in the Little array on the next in the following format: “Big: {numbers}” and “Little: {numbers}”. Separate numbers on each line by a space, but do NOT include space at the end of the lines. For example:
>4
>101
>756
>3
>255
Big: 101 756 255
Little: 3
Here is my code:
namespace Arrays
{
class SplitArray
{
public static void Main(string[] args)
{
int[] myArray = GetNumbersFromConsole();
int[] myArrayBig = new int[myArray.Length];
int[] myArrayLittle = new int[myArray.Length];
int bigIndex = 0;
int littleIndex = 0;
for (int i = 0; i < myArray.Length; ++i)
{
if (myArray[i] > 100)
myArrayBig[bigIndex++] = myArray[i];
else
myArrayLittle[littleIndex++] = myArray[i];
}
Console.Write("Big:");
for (int i = 0; i < myArrayBig.Length; i++)
{
Console.Write(" ");
if (myArrayBig[i] != 0)
Console.Write(myArrayBig[i]);
}
Console.WriteLine();
Console.Write("Little:");
for (int i = 0; i < myArrayLittle.Length; i++)
{
Console.Write(" ");
if (myArrayLittle[i] != 0)
Console.Write(myArrayLittle[i]);
}
}
static int[] GetNumbersFromConsole()
{
int count = int.Parse(Console.ReadLine());
int[] result = new int[count];
for(int i = 0; i < count; ++i)
{
result[i] = int.Parse(Console.ReadLine());
}
return result;
}
}
}
Can anyone please help me to solve it?
Мій код видає потрібний результат, але чомусь кодізі його не приймає. Чому?