这次不仅有截图,更有代码!
static void Main(string[] args)
{
string s = Console.ReadLine();
int n;
bool isn = int.TryParse(s,out n);
if (!isn)
{
Console.WriteLine("非法字符!");
}
else if (n < 3 || n > 21)
{
Console.WriteLine("超出列数范围!");
}
else
{
for (int k = 0; k < n; k++)
{
for (int i = 0; i < n - k-1; i++)
{
Console.Write(" ");
}
for (int j = 0; j <2*k+1; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
for (int k = n; k > 0; k--)
{
if (k == 1)
{
Console.Write("");
}
else
{
for (int i = 0; i < n - k + 1; i++)
{
Console.Write(" ");
}
for (int j = 0; j < 2*k - 3; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
Console.ReadKey();
}
}
|
|