I have the following very basic code:
static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < n*3; i++) { string[] numbers = Console.ReadLine().Split(); Console.WriteLine(); Console.WriteLine(numbers[i]); } }
It's supposed to take the following data:
3
11 9 1
14 90 232
111 15 111
It is taking the first number to determine the number of lines of data their are (there is a reason for this but outside of the scope of this question.
The loop should take line 2, 3 and 4 and populate the numbers array, splitting the data up so numbers[0] = 11, numbers[1] = 9, numbers[2] = 1... and so on.
What I'm seeing is that it's putting the first number in the line into the array and moving on. Here is a preview of what it's doing currently:
3
11 9 1
11
14 90 232
90
111 15 111
I was hoping the output would be:
3
11 9 1
11 9 1
14 90 232
14 90 232
111 15 111
111 15 111
I'm probably doing something completely stupid and blatantly obvious but I'm still trying to learn C#.
Console.WriteLine(numbers[i]);
to print multiple numbers? – Jon SkeetBanana
instead of a number. See what's going on there. – Zohar Peled