我无法让 4 种不同的三角形图案并排出现。这是一个控制台应用程序。
这正是我试图通过使用嵌套 for 循环来实现的目标:
* ******************** *
** ********* ********* **
*** ******** ******** ***
**** ******* ******* ****
***** ****** ****** *****
****** ***** ***** ******
******* **** **** *******
******** *** *** ********
********* ** ** *********
*********** ***********
我已经让单独的模式工作了,但当然它们会一个接一个地出现。
using System;
class Assignment5
{
static void Main()
{
for (int i = 1; i <= 10; i++) // Outer loop for number of rows
{
for (int j = 1; j <= i; j++) // Inner loop for number of stars
{
Console.Write("*");
}
Console.WriteLine();
} // End First Pattern
for (int i = 10; i >= 1; i--) // Outer loop for number of rows
{
for (int j = 1; j <= i; j++) // Inner loop for number of stars
{
Console.Write("*");
}
Console.WriteLine();
} // End Second Pattern
for (int i = 10; i >= 1; i--) // Outer Loop for number of rows
{
for (int j = 1; j <= 10 - i; j++) //Inner loop for number of spaces
{
Console.Write(" ");
}
for (int k = 1; k <= i; k++) //Secondary inner loop for number of stars
{
Console.Write("*");
}
Console.WriteLine();
} // End Third Pattern
for (int i = 1; i <= 10; i++) //Outer Loop for number of rows
{
for (int j = 1; j <= 10 - i; j++) //Inner loop for number of spaces
{
Console.Write(" ");
}
for (int k = 1; k <= i; k++) //Secondary inner loop for number of stars
{
Console.Write("*");
}
Console.WriteLine();
} // End Fourth Pattern
Console.WriteLine("Press Enter for Part 2 of this Program");
Console.ReadKey();
Console.Clear();
} // End main function
} // End class Assignment5