如果有任何身体,我去做星星作为答案好吗? [英] I went to make Star if any body as Answer please ?

查看:51
本文介绍了如果有任何身体,我去做星星作为答案好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//Star  this is my C#  code in console application 

            Console.WriteLine("Program for displaying pattern of *.");
            Console.Write("Enter the maximum number of *: ");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("\nHere is the Diamond of Stars\n");

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


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

        }
    }





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



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

推荐答案

我带着这个代码去制作星星

但是一方制作了如何工作的明星哦




首先看看你想要展示的形状是如何构成的。

例如钻石形状:



"i went to make Star with this code
but One side Made how work on ohter of star"


Start by looking at how the shape you are trying to show is made up.
For example a Diamond shape:

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

意思是:

Means:

Output 2 spaces, output 1 star
Output 1 space,  output 3 stars
Output 0 spaces, output 5 stars
Output 1 space,  output 3 stars
Output 2 spaces, output 1 stars



看一下,很明显你需要三个循环:一个绕着外面输出行数,两个在中间输出第一个正确数量的空格,然后是正确的数字明星。



所以你想要的代码类似于:


Looking at that, it's obvious that you will need three loops: one round the outside to output the number of lines, and two in the middle to output first the right number of spaces, then the right number of stars.

So you would want code similar to:

for (int line = 0; line < lineCount; line++)
   {
   for (int space = 0; ...
      {
      // print spaces
      }
   for (int star = 0; ...
      {
      // print stars
      }
   }

每次打印的空格和星星数量取决于行的值



你可能会发现最好有两个外环:一个打印顶部,空格减少,星形增加,然后一个打印底部,空格增加,星星减少。 (我会,代码更容易)



我不知道你的形状是什么 - 即使我运行你的代码也不行 - 所以我不能告诉你到底要做什么来制作你的形状。但希望如果仔细观察你的形状,那应该是非常明显的。

And the number of spaces and stars printed each time will depend on the value of line

You might find it better to have two outer loops: one to print the top, with spaces decreasing and stars increasing, followed by one to print the bottom, with spaces increasing and stars decreasing. (I would, it's a lot easier to code)

I can't tell what your shape is - not even if I run your code - so I can't tell you exactly what to do to produce your shape. But hopefully if you look at your shape carefully, it should be pretty obvious.


这篇关于如果有任何身体,我去做星星作为答案好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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