使用forloop在控制台应用程序中打印 [英] print in console application by using forloop

查看:72
本文介绍了使用forloop在控制台应用程序中打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1
212

32123

4321234

在控制台窗口中打印

1 212
32123
4321234
print this in console window

推荐答案

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



亲自尝试,你可能会发现它不是和你想的一样困难!

如果你遇到困难,那就问一下 - 但这是你的任务,我们不会为你做的!





我做到了......用五条条件......





:笑:

看看每个条件。如果i是n,那么你从n开始k...那么为什么要检查i值,而只是从i开始k循环?



时间让你摆脱痛苦,你足够接近!

这是我的版本:

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!
If you get stuck on a particular bit, then ask about that - but this is your task, and we will not do it for you!


I did It....By Using Five If Conditions......


:laugh:
Look at each if condition. If "i" is "n" then you start "k" from "n"...so why check the "i" value, instead just start the "k" loop from "i"?

Time to put you out of your misery, you are close enough!
Here is my version:
for (int i = 1; i <= 5; i++)
    {
    for (int k = i; k > 1; k--)
        {
        Console.Write(k + " ");
        }
    for (int j = 1; j <= i; j++)
        {
        Console.Write(j + " ");
        }
    Console.WriteLine();
    }



你明白我的意思吗?这有意义吗?


Do you see what I mean now? Does that make sense?


static void Main(string[] args)
       {
           for (int i = 1; i <= 5; i++)
           {
               for (int j = i; j > 1; j--)
               {
                   Console.Write(j+" ");
               }
               for (int k = 1; k <= i; k++)
               {
                   Console.Write(k+" ");
               }
               Console.WriteLine();
           }
       }


这篇关于使用forloop在控制台应用程序中打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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