算法一
static void Main(string[] args)
{
string str = "*";
for (int i = 0; i <= 6; i++)//控制大小
{
Console.Write(str.PadLeft(i + 1));
for (int j = i; j <= 5; j++)//控制输出
{
Console.Write(str.PadLeft(2));
}
Console.WriteLine();
}
Console.ReadLine();
}
算法二
private static void DoStar(int i) {
if (i > 0)
{
string str = "*";
Console.Write(str.PadLeft(11-i));
for (int j = 0; j <= i-2; j++)
{
Console.Write(str.PadLeft(2));
}
Console.WriteLine();
DoStar(--i);
}
}
算法三
List<string> list = new List<string>();
StringBuilder sb = new StringBuilder();
int total = 10;
int index = 0;
for (index = 0; index < total; index++)
{
string temp = "*";
temp = temp.PadLeft(total - index).PadRight(total + index, '*');
list.Add(temp);
sb.AppendLine(temp);
}
//for (index = list.Count - 2; index >= 0; index--)
//{
// sb.AppendLine(list[index]);
//}
//for (index = 0; index < list.Count; index++)
//{
// sb.AppendLine(list[index]);
//}
Console.Write(sb.ToString());
Console.ReadKey();