I am making a two dimensional array (soccer matrix)I have already made my arrays, datacolumn and rows.
How do i make my matrix like this below? and get the right input everywhere
2010-2011 England Germany Holla开发者_StackOverflownd Spain Germany Russia Japan
England x
Germany x
Holland x
Spain x
Germany x
Russia x
Japan x
This all will be made into a console application.
Best regards,
int rows = 8;
int colums = 8;
String[,] data = new String[colums, rows];
int x = 0;
int y = 0;
for(; y < rows; y++)
{
for (; x < colums; x++)
{
Console.Write(data[x, y] + " ");
if (x == (colums - 1))
{
Console.WriteLine("");
Console.WriteLine("");
}
}
x = 0;
}
int userSelectedHomeTeam
int userSelectedAwayTeaM
Console.WriteLine("Select home team by the number")
for(int i = 1; i < colums; i++)
{
Console.WriteLine(data[i, 0] + " " + i)
}
str = Console.ReadLine();
userSelectedHomeTeam = Int32.Parse(str);
Console.WriteLine("Select away team by the number")
for(int i = 1; i < colums; i++)
{
Console.WriteLine(data[i, 0] + " " + i)
}
str = Console.ReadLine();
userSelectedAwayTeam = Int32.Parse(str);
Console.WriteLine("Write user input")
str = Console.ReadLine();
data[userSelectedHomeTeam , userSelectedAwayTeam ] = str;
To output it all you need do is:
int numberRows = dataArray.GetUpperBound(0);
int numberColumns = dataArray.GetUpperBound(1);
for (int i = 0; i <= numberRows ; i++)
{
for (int j = 0; j <= numberColumns ; j++)
{
Console.WriteLine(string.Format("({0,8}) ", dataArray[i, j]));
}
Console.WriteLine();
}
Just use string padding for the output, so that each column data appears under the correct team name, i've used 8 you will need to adjust this for however wide each column is.
精彩评论