C#编程,输出一个正方形(由*组成,当然空心),帮我一下吧
4个回答
展开全部
for (int i = 0; i < 10; i++)
{
if (i != 0 || i != 9)
{
Console.Write("*");
}
for (int j = 0; j < 10; j++)
{
if (i == 0 || i == 9)
{
Console.Write("*");
}
else
{
Console.Write(" ");
}
}
if (i != 0 || i != 9)
{
Console.Write("*");
}
Console.WriteLine();
}
---------------------------------希望能帮到你,还不怎么是正方形,稍稍修改显示个数就ok了--------------------------------
{
if (i != 0 || i != 9)
{
Console.Write("*");
}
for (int j = 0; j < 10; j++)
{
if (i == 0 || i == 9)
{
Console.Write("*");
}
else
{
Console.Write(" ");
}
}
if (i != 0 || i != 9)
{
Console.Write("*");
}
Console.WriteLine();
}
---------------------------------希望能帮到你,还不怎么是正方形,稍稍修改显示个数就ok了--------------------------------
追问
加me, 帮我操作一下 visual stdio express 2013 for desktop,麻烦你了,
101 49 07 148
展开全部
static void Main(string[] args)
{
do
{
Console.WriteLine("请输入正方形宽度:");
string str = Console.ReadLine();
int number;
if (int.TryParse(str, out number))
{
DrawSquare(number);
}
else
{
Console.WriteLine("输入格式不正确!");
}
}
while (true);
}
public static void DrawSquare(int number)
{
if (number >= 2)
{
string firstlast = "";
string center = "";
for (int i = 0; i < number; i++)
{
firstlast += "*";
if (i != 0 && i != number - 1)
{
center += " ";
}
}
center = "*" + center + "*";
for (int i = 0; i < number; i++)
{
if (i != 0 && i != number - 1)
{
Console.WriteLine(center);
}
else
{
Console.WriteLine(firstlast);
}
}
}
}
{
do
{
Console.WriteLine("请输入正方形宽度:");
string str = Console.ReadLine();
int number;
if (int.TryParse(str, out number))
{
DrawSquare(number);
}
else
{
Console.WriteLine("输入格式不正确!");
}
}
while (true);
}
public static void DrawSquare(int number)
{
if (number >= 2)
{
string firstlast = "";
string center = "";
for (int i = 0; i < number; i++)
{
firstlast += "*";
if (i != 0 && i != number - 1)
{
center += " ";
}
}
center = "*" + center + "*";
for (int i = 0; i < number; i++)
{
if (i != 0 && i != number - 1)
{
Console.WriteLine(center);
}
else
{
Console.WriteLine(firstlast);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
consloe.writeline("************************************");
consloe.writeline("* *");
consloe.writeline("************************************");
consloe.writeline("* *");
consloe.writeline("************************************");
追问
等我加上循环试试
追答
好了的话,采纳一下吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
...... 这问题有意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询