必需的输出是:
******
** **
* *
** **
******
我编写了以下代码来实现它:
int n = 5;
for (int i = n; i >= 1; i--)
{
for (int j =n-1; j >= n-i; j--)
{
if ((i == j && j > i) || (j == i && i > j))
Console.Write("*");
else
Console.Write("3");
}
Console.WriteLine();
}
for (int i = n; i >= 1; i--)
{
for (int j = i; j <= n; j++)
{
if ((i == j && j > i) || (j == i && i > j))
Console.Write("*");
else
Console.Write("3");
}
Console.WriteLine();
}
Console.ReadLine();
但我的代码是打印:
33333
3333
333
33
3
3
33
333
3333
33333
如何修复我的代码以打印明星钻石?
答案 0 :(得分:2)
你能不能以简单的方式做到这一点?
<field name="date" position="before">
<field name="name"/>
</field>
答案 1 :(得分:0)
试试这个:
int number = 5;
for (int i = 0; i < number; i++)
{
var starsCount = 1 + Math.Abs(Math.Floor(number / 2.0) - i);
var spacesCount = 1 + Math.Floor(number / 2.0) - starsCount;
var output = "";
for (int j = 0; j < starsCount; j++)
output += "*";
for (int k = 0; k < spacesCount; k++)
output += " ";
for (int m = 0; m < starsCount; m++)
output += "*";
Console.WriteLine(output);
}