标签:c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace demo
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 5; i++) {
for (int k = 5; k >= i; k--) {
Console.Write(" ");
}
for (int j = 1; j <= i; j++) {
Console.Write("*");
}
for (int h = 1; h < i; h++) {
Console.Write("*");
}
Console.WriteLine();
}
for (int i = 4; i >=0; i--)
{
for (int k = 6; k>i; k--)
{
Console.Write(" ");
}
for (int j = 1; j <= i; j++)
{
Console.Write("*");
}
for (int h = 1; h < i; h++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
运行结果是这样的:
*
***
*****
*******
*********
*******
*****
***
*
总结:代码不够紧凑、也不够专业,循环太多,浪费时间,寻找更好的解决方案。
本文出自 “phize” 博客,请务必保留此出处http://12756301.blog.51cto.com/12746301/1970075
标签:c#
原文地址:http://12756301.blog.51cto.com/12746301/1970075