在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
分析:
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
相关文章推荐
- Django的template自定义函数的创建和使用
- EntityFramework4.5使用Expression类创建动态查询及动态查询导航属性
- EntityFramework4.5使用Expression类创建动态查询及动态查询导航属性
- javascript中创建自定义类型的最常见的方式_组合使用构造函数模型和原型模式,动态原型模式
- 使用Django创建动态页面
- Django创建自定义filter来使用bootstrap
- Java创建自定义标签SimpleTagSupport并在页面中使用
- SilverlightLoader使用托管代码创建自定义载入界面及动态加载XAP
- Excel--使用VBA Code 动态创建、修改和删除自定义窗体代码摘抄
- How to create custom navigation menu in SharePoint with XML data source 使用XML数据源在SharePoint创建自定义导航菜单
- Django:(博客系统)使用使用mysql数据&创建post/category/tag实体,并同步到数据中
- EntityFramework4.5使用Expression类创建动态查询及动态查询导航属性
- How to create custom navigation menu in SharePoint with XML data source 使用XML数据源在SharePoint创建自定义导航菜单
- 创建动态导航(使用SqlSiteMapProvider)
- 使用django-admin创建项目出错,can't open file 'django-admin.py'
- 使用jquery.fullpage.js需要动态改变导航小圆点的样式
- Django使用自定义认证方式
- Android Training - 使用碎片创建一个动态UI(1) - 使用android支持库
- VS2003 C#:重写键盘响应事件、动态创建控件、创建线程、在线程中使用委托在界面显示数据
- Tag c#,c++创建动态库