A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 蔡嘉 中级黑马   /  2012-9-25 00:17  /  2373 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

这次不仅有截图,更有代码!
static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n;
            bool isn = int.TryParse(s,out n);
            if (!isn)
            {
                Console.WriteLine("非法字符!");
            }
            else if (n < 3 || n > 21)
            {
                Console.WriteLine("超出列数范围!");
            }
            else
            {
                for (int k = 0; k < n; k++)
                {
                    for (int i = 0; i < n - k-1; i++)
                    {
                        Console.Write(" ");
                    }
                    for (int j = 0; j <2*k+1; j++)
                    {
                        Console.Write("*");

                    }
                    Console.WriteLine();
                }
                for (int k = n; k > 0; k--)
                {
                    if (k == 1)
                    {
                        Console.Write("");
                    }
                    else
                    {
                        for (int i = 0; i < n - k + 1; i++)
                        {
                            Console.Write(" ");
                        }
                        for (int j = 0; j < 2*k - 3; j++)
                        {
                            Console.Write("*");
                        }
                        Console.WriteLine();
                    }
                    
                }
               
               
                Console.ReadKey();

            }
        }

菱形.png (10.5 KB, 下载次数: 34)

菱形.png

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

4 个回复

倒序浏览
楼主你干嘛啊。。。。这不是最基本的东西吗?怎么在这可劲发啊。。
回复 使用道具 举报
不会再发了,已经是结尾了。
I'm so sorry!
回复 使用道具 举报
.....四個方向都發一邊,再來個東南,西南,西北,東北,然後再來個圓的,再來個正方形的,長方形的,橢圓的,五角的,六角的,七角的,八角的.....分就賺到了
回复 使用道具 举报
using System;

namespace 菱形输出
{
        class Program
        {
                public static void Main(string[] args)
                {
                        int Row;
                        Console.Write("请输入行数(3-21):");
                        while(!int.TryParse(Console.ReadLine(),out Row)||Row<3||Row>21)
                        {
                                Console.Write("输入错误,请重新输入行数(3-21):");
                        }
                        for(int i=1;i<=Row;i++)
                        {
                                for(int j=1;j<=Row-i;j++)
                                {
                                        Console.Write(" ");
                                }
                                for(int j=1;j<=2*i-1;j++)
                                {
                                        Console.Write("*");
                                }
                                Console.WriteLine();
                        }
                        for(int i=Row;i>=1;i--)
                        {
                                for(int j=1;j<=Row-i;j++)
                                {
                                        Console.Write(" ");
                                }
                                for(int j=1;j<=2*i-1;j++)
                                {
                                        Console.Write("*");
                                }
                                Console.WriteLine();
                        }
                        Console.ReadKey(true);
                }
        }
}

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马