zoukankan      html  css  js  c++  java
  • C#在屏幕上输出一个5行5列的菱形

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 打印一个菱形
    {
        class Program
        {
        ///
        /// 在屏幕上输出一个菱形,5行5列
        ///
        ///   *
        ///  ***
        /// *****
        ///  ***
        ///   *
        /// 将菱形分成两部分输出,上半部分3行,下半部分2行
            static void Main(string[] args)
        {
          for (int i = 1; i <= 3; i++) //上半部分菱形的行数
          {
            for (int j = 0; j < 3 - i; j++) //每行打印空格的个数
            {
               Console.Write(" ");
            }
            for (int k = 0; k < 2 * i - 1; k++) //每行打印*的个数
            {
              Console.Write("*");
            }
            Console.WriteLine();
          }
          for (int i = 1; i <= 2; i++) //下半部分菱形的行数
          {
            for (int j = 0; j < i; j++) //每行打印空格的个数
            {
              Console.Write(" ");
            }
            for (int k = 0; k <= 4 - 2 * i; k++) //每行打印*的个数
            {
              Console.Write("*");
            }
            Console.WriteLine();
          }
          Console.ReadKey();
        }
      }
    }
  • 相关阅读:
    给定中序和后序遍历,求前序序列(C++递归方式实现)
    myeclipse2014删除antlr-2.7.2.jar--解决struts和hibernate包冲突
    hadoop1.2.1配置与运行子串统计程序
    任务计划crontab
    建NTP
    vnc下运行runInstall报java错误
    rpm软件安装
    redis
    rpm包和deb包转换
    新老版本centos下载
  • 原文地址:https://www.cnblogs.com/ahhswyf/p/3434004.html
Copyright © 2011-2022 走看看