【发布时间】:2015-10-11 17:36:18
【问题描述】:
我需要在控制台中编写代码,使行号出现在行上它的自身以及它在行上的位置。我的程序只输出一行 *****,我似乎无法让它变得更多。帮助将是惊人的提前感谢堆
eg 1*****
*2****
**3***
***4**
我现在有,
static void Main(string[] args)
{
int n = 0;
string s = "";
//check if 2 args
if (args.Length == 2)
{
if (int.TryParse(args[0], out n))
{
//successful parse, so use n
s = args[1]; //second argument is character
//draw a line of characters
DrawChars(n, s);
}
else
{
//unsuccessful parse, so no n value
}
}
//wait for user to have read output
Console.WriteLine();
Console.Write("Press enter to finish:");
Console.ReadLine();
}
/// <summary>
/// Method to draw a line of characters
/// </summary>
/// <param name="n">number of characters to draw</param>
/// <param name="s">character to draw n times</param>
static void DrawChars(int n, string s)
{
for (int i = 1; i <= n; i++)
{
Console.Write(s);
}
Console.WriteLine();
}
【问题讨论】:
-
s="" 不是 "D" 并且我将 n 设置为 0