您的位置:首页 > 其它

打印等腰三角形行号限制为3~21

2012-09-19 17:42 106 查看
using System;

using System.Collections.Generic;

using System.Text;

namespace triangle

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("请输入数字");

int j = Convert.ToInt32(Console.ReadLine());

Program p = new Program();

p.test(j);

}

public void test(int i)

{

if (i < 3 || i> 21)

{

Console.WriteLine("非法行数");

Console.ReadLine();

return;

}

for (int k = i; k <= i; k--)

{

if (k > 0)

{

for (int j = 0; j < i - k; j++)

{

Console.Write(" ");

}

for (int a = 1; a <= (2 * k) - 1; a++)

{

if (a > 0)

{

Console.Write("*");

}

}

Console.WriteLine("");

}

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐