如何生成A“*”方形格式的符号 [英] How Do I Generate A "*" Symbol In A Square Format

查看:119
本文介绍了如何生成A“*”方形格式的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以方框格式打印星星

i want to print the star in box format

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







我需要做什么






what i need to do

for (int i = 0; i < 3; i++)
           {
               for (int j = 0; j <= i; j++)
               Console.Write("*");
               Console.WriteLine();



[edit]已添加代码块 - OriginalGriff [/ edit]


[edit]Code block added - OriginalGriff[/edit]

推荐答案

我们做不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是你想的很难!



但是......这几乎是微不足道的:



1)打印顶线。

2)循环中间线

2.1)打印左边缘

2.2)循环空白 - 打印它们所有

2.3)打印右边缘和新线

3)打印底线。



我,我会做两个方法:PrintRowOfStars做顶部和底部,PrintBoxRow做中心。两种方法都需要一个参数 - 行的长度 - 并打印许多字符和换行符。
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

But...this is almost trivial:

1) Print the top line.
2) Loop for the middle lines
2.1) Print the left edge
2.2) Loop for the blanks - print them all
2.3) Print the right edge, and a new line
3) Print the bottom line.

Me, I'd make two methods: PrintRowOfStars to do the top and bottom, and PrintBoxRow to do the centres. Both methods would take a parameter - the length of the line - and print that many characters and a newline.


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

namespace starbox
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 1; i++)
            {
                for (int j = 0; j <= 3; j++) //to print the first line
                    Console.Write("*");
                Console.WriteLine(""); //to go to second line
            }
           for (int i = 0; i <=1; i++) //to repeat for two times 
            {

                for (int j = 0; j<=0; j++)
              // Console.WriteLine("");
                    Console.Write("*"); // to print in second row and first column
               for (int j=1;j<=2;j++)
                   Console.Write(" "); // to bring two spaces for next *
               for (int j = 3; j <= 3; j++)
                   Console.Write("*"); // to print star in second row and last column
               Console.WriteLine();      
            }
                for (int i = 3; i < 4; i++)
                {

                    for (int j = 0; j <= 3; j++)

                      Console.Write("*");
                    //Console.WriteLine("");
                }
                Console.ReadKey();
            }
        }
    }


这篇关于如何生成A“*”方形格式的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆