我目前有一个2D字符串数组的代码,旨在保存一周的5天和5个数字值。请注意,这是在C#的控制台应用程序中。
我唯一的问题是在用户端输入数据有点令人困惑,因为就目前情况而言,我必须连续输入所有10个数据值。没有什么可以把日子和数字分开了。
我希望在用户输入前5天后进行对话,告诉他们现在输入数字数据。
有其他不同的方法吗?
当前代码如下所示。
//Ask the user to enter five days of the week and rainfall data for each day
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("\n5. Please enter five days of the week.");
//Store the data in a two dimensional string array named rainfallData[]
Console.ForegroundColor = ConsoleColor.White;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 5; j++)
{
rainfallData[i, j] = Console.ReadLine();
}
}
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("Doubles placed in myDoubles[] array.");
Console.ForegroundColor = ConsoleColor.White;
for (int i = 0; i < 2; i++)
{
Console.WriteLine();
for (int j = 0; j < 5; j++)
{
Console.WriteLine("rainfallData({0},{1})={2}", i, j, rainfallData[i, j]);
}
}
要在输入前5条消息后显示消息,请添加其他if语句和控制台输出。
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 5; j++)
{
rainfallData[i, j] = Console.ReadLine();
}
if(i == 0)
{
Console.WriteLine("Enter rain data");
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句