码迷,mamicode.com
首页 > 其他好文 > 详细

for嵌套用法 选择图形 举例

时间:2015-04-01 17:28:30      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

static void Main(string[] args)
{
while (true)
{
Console.Write("请选择您想要得到的图形?A正方形;B三角形;C平行四边形;D菱形;E梯形:");
string n = Console.ReadLine();
Console.Write("请输入数字:");
int m = Convert.ToInt32(Console.ReadLine());
switch (n)
{
case "A":
for (int i = 1; i <= m; i++)
{
Console.Write("☆");

for (int j = 1; j <= m; j++)
{
Console.Write("☆");
}
Console.Write("\n");
}
break;
case "B":
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= m - i; j++)
{
Console.Write(" ");
}
for (int k = 1; k <= 2 * i - 1; k++)
{
Console.Write("☆");
}
Console.Write("\n");
}
break;
case "C":
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <=m-i; j++)
{
Console.Write(" ");
}
for (int k =1; k <= m; k++)
{
Console.Write("?");
}
Console.Write("\n");
}
break;
case "D":
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= m - i; j++)
{
Console.Write(" ");
}
for (int k = 1; k <= 2 * i - 1; k++)
{
Console.Write("☆");
}
Console.Write("\n");
}
for (int p = 1; p <= m; p++)
{
for (int q = 1; q <= p; q++)
{
Console.Write(" ");
}
for (int h = 1; h <= 2 *(m-p) - 1; h++)
{
Console.Write("★");
}
Console.Write("\n");
}
break;
case "F":
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= m - i; j++)
{
Console.Write(" ");
}
for (int k = 1; k <= 2 * i + 3; k++)
{
Console.Write("☆");
}
Console.Write("\n");
}
break;
default:
Console.Write("您的输入有误!");
break;
}
Console.ReadLine();
}
}

for嵌套用法 选择图形 举例

标签:

原文地址:http://www.cnblogs.com/dlexia/p/4384192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!