您的位置:首页 > 编程语言 > Go语言

在Django中使用自定义Tag创建动态导航栏

2008-04-11 10:41 621 查看
题目:输出n行三角形*号图形。
分析:
1.n行必须有n次循环.
2.占位孔符为n-i(n为总行数,i为当前要打印的行数).
3.要输出的*的个数为2*i-1(i为当前要打印的行数).
程序实现:


using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


using System.Threading.Tasks;




namespace Triangle


{


class Program


{


static void Main(string[] args)


{


while (true)


{


Console.WriteLine("Please put in an angument for create triangle:");




try


{


string inputstr=Console.ReadLine();


int n = Int32.Parse(inputstr);


if (n < 0) continue;


DrawTriangle(n);


}


catch (Exception)


{


Console.WriteLine("Invalidate argument! Please put in again:");


continue;


}


}


}


static void DrawTriangle(int n)


{


for (int i =1; i <=n; i++)


{


//输出占位符


for (int j = 1; j <=n-i; j++)


{


Console.Write(" ");


}


//输出*


for (int j = 1; j <=2*i-1; j++)


{


Console.Write("*");


}


//输出每一行后换行


Console.WriteLine();


}


}


}


}

运行结果:


本文出自 “程序人生” 博客,请务必保留此出处http://jizhonglee.blog.51cto.com/3003732/1157021
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐