Console.WriteLine("请输入等边三角形高度:");
string line = Console.ReadLine();
int height = 3;
if (false == int.TryParse(line, out height))
{
Console.WriteLine("输入高度不是合法整数,默认高度3执行");
}
for (int h = 0; h < height; h++)
{
for (int idx = 0; idx <= 2 * height - 1; idx++)
{
if (idx > height - h - 1 && idx <=height - h - 1 + 2 * h + 1)
{
Console.Write("*");
}
else
{
Console.Write(" ");
}
}
Console.WriteLine();
}
Console.Write("按任意键退出程序");
Console.ReadKey();