I have school assignment to create console program that creates a Field of Numbers (rectangular shape) with the Input of the User using basic for
loop. Meaning, the User will write which Number should be used to fill the Field, and how high and wide the Field should be.
我有学校作业创建控制台程序,使用基本for循环创建一个数字域(矩形)与用户的输入。意思是,用户将写入应该使用哪个数字来填充字段,以及字段应该有多高和多宽。
Here is the Code:
这是代码:
Console.WriteLine("Hey! Which Number do you want to use to fill the field?");
int fieldNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Okay, how big should be the lenght?");
int fieldSizeX = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Allright, how big should the height be?");
int fieldSizeY = Convert.ToInt32(Console.ReadLine());
Console.Clear();
for (int i = 0, j = 0; i < fieldSizeX && j < fieldSizeY; i++, j++)
{
}
1 个解决方案
#1
Split the loops apart, you need to write out X*Y elements.
将循环分开,你需要写出X * Y元素。
//For each row (y)
for (int y = 0; y < fieldSizeY; y++)
{
//For each column (x)
for (int x = 0; x < fieldSizeX; x++)
{
//Now you need to repeat the same number for each x, but no new line.
Console.Write(fieldNumber)
}
//Stick the new line on the end of the row to start the next row
Console.WriteLine();
}
#1
Split the loops apart, you need to write out X*Y elements.
将循环分开,你需要写出X * Y元素。
//For each row (y)
for (int y = 0; y < fieldSizeY; y++)
{
//For each column (x)
for (int x = 0; x < fieldSizeX; x++)
{
//Now you need to repeat the same number for each x, but no new line.
Console.Write(fieldNumber)
}
//Stick the new line on the end of the row to start the next row
Console.WriteLine();
}