当前位置: 代码迷 >> ASP.NET >> 小弟刚刚接触C#,在这里求一代码,给个思路也行
  详细解决方案

小弟刚刚接触C#,在这里求一代码,给个思路也行

热度:4142   发布时间:2013-02-26 00:00:00.0
小弟刚接触C#,在这里求一代码,给个思路也行~
用c#
输出为:
----*
---*-*
--*-*-*
-*-*-*-*
*-*-*-*-*  


------解决方案--------------------------------------------------------
没啥要求吗?那这样好了:

Console.WriteLine( "----* ");
Console.WriteLine( "---*-* ");
Console.WriteLine( "--*-*-* ");
Console.WriteLine( "-*-*-*-* ");
Console.WriteLine( "*-*-*-*-* ");
Console.ReadLine();


------解决方案--------------------------------------------------------
for(int i=1;i <=5;i++)
{
for(int j=1;j <=5-i;j++)
{
Console.Write( "- ");
}
for(int k=1;k <i;k++)
{
Console.Write( "*- ");
}
Console.WriteLine( "* ");

}
Console.ReadLine();
------解决方案--------------------------------------------------------
呵呵.再改一下:

public static void Main()
{
Test(12,12);
Console.ReadLine();
}

private static void Test(int row,int col)
{
for(int i=1;i <=row;i++)
{
for(int j=1;j <=col-i;j++)
{
Console.Write( "- ");
}
for(int k=1;k <i;k++)
{
Console.Write( "*- ");
}
Console.WriteLine( "* ");
}
}
------解决方案--------------------------------------------------------
输出等腰三角形
using System;
using System.Collections;

namespace ConsoleApplication1
{

class Program
{

static void Main(string[] args)
{
Out3(7);

}
static void Out3(int iStep)
{
int iMax = 2 * iStep - 1;//最多的星号
string sPrefix = " ";//前面的后格
string sOther = " ";
string sStar = "* ";

for (int i = 1; i <= iStep; i++)
{
Console.Write(sPrefix);
for (int j = 0; j < iMax / 2 + 1 - i; j++)
Console.Write(sOther);
int count = 2 * i - 1;
for (int j = 0; j < count; j++)
Console.Write(sStar);
Console.WriteLine();
}
}

}


}


  相关解决方案