在C#控制檯輸出的愛心圖案
阿新 • • 發佈:2018-11-20
class
DrawHeart
{
static
void
Main()
{
for
(
int
i = 0, m = 1; i < 30; i++)
for
(
int
l = 0; l <
new
[] { 5, 6, 7, 6, 8, 10, 3, 10, 4, 13, 1, 13, 1, 87, 1, 27, 4, 23, 7, 20, 11, 16, 16, 11, 20, 7, 24, 3, 27, 1 }[i]; l++, m++)
System.Console.Write((i % 2 > 0 ?
"love"
[m % 4] :
' '
) + (m % 29 > 0 ?
""
:
"\n"
));
Console.ReadLine();
}
}
第二個
string outString = "*";//輸出的字
for (int i = 1; i <= 8; i++)
{
for (int j = 1; j <= 9; j++)
{
if (((i == 1) && ((j == 5) || (j == 1) || (j == 9))) || ((i >= 4) && ((j <= i - 3) || (j >= 13 - i))))
{
Console.Write(" ");
}
else
{
Console.Write(" "+outString);//英文或是字元,符號輸出方式
// Console.Write(outString);//中文輸出方式
}
}
Console.WriteLine("");
}
for (int i = 1; i <= 8; i++)
{
for (int j = 1; j <= 9; j++)
{
if (((i == 1) && ((j == 5) || (j == 1) || (j == 9))) || ((i >= 4) && ((j <= i - 3) || (j >= 13 - i))))
{
Console.Write(" ");
}
else
{
Console.Write(" "+outString);//英文或是字元,符號輸出方式
// Console.Write(outString);//中文輸出方式
}
}
Console.WriteLine("");
}