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[] numbers = GetNumbersFromConsole();
int[] bigNumbers = new int[numbers.Length];
int bigCount = 0;
int[] littleNumbers = new int[numbers.Length];
int littleCount = 0;
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] > 100)
{
bigNumbers[bigCount] = numbers[i];
bigCount++;
}
else
{
littleNumbers[littleCount] = numbers[i];
littleCount++;
}
}
Console.Write($"Big: ");
for (int i = 0; i < littleCount; i++)
{
Console.Write($"{bigNumbers[i]} ");
}
Console.WriteLine();
Console.Write($"Little: ");
for (int i = 0; i < littleCount; i++)
{
Console.Write($"{littleNumbers[i]} ");
}
Console.WriteLine();
// Write your code here
}
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?