码迷,mamicode.com
首页 > Windows程序 > 详细

用C#代码在控制台上打印图案

时间:2017-10-01 15:48:49      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace demo
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 5; i++) {

                for (int k = 5; k >= i; k--) {
                    Console.Write(" ");
                }
                for (int j = 1; j <= i; j++) {
                    Console.Write("*");
                }
                for (int h = 1; h < i; h++) {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            for (int i = 4; i >=0; i--)
            {

                for (int k = 6; k>i; k--)
                {
                    Console.Write(" ");
                }
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("*");
                }
                for (int h = 1; h < i; h++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
    }
}
运行结果是这样的:

     *
    ***
   *****
  *******
 *********
  *******
   *****
    ***
     *

总结:代码不够紧凑、也不够专业,循环太多,浪费时间,寻找更好的解决方案。

本文出自 “phize” 博客,请务必保留此出处http://12756301.blog.51cto.com/12746301/1970075

用C#代码在控制台上打印图案

标签:c#

原文地址:http://12756301.blog.51cto.com/12746301/1970075

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!