我想快速解释一下这段代码 [英] i want a real quick explanation of this code

查看:60
本文介绍了我想快速解释一下这段代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

相反解释代码,我建议你阅读C#编程书或教程。



从这里开始:

for(C#Reference) [ ^ ]

C#教程 [ ^ ]

C#编程指南 [ ^ ]
Instead explaining code, i would recommend you to read C# programming book or tutorial.

Start here:
for (C# Reference)[^]
C# Tutorials[^]
C# Programming Guide[^]


您稍微修改了您的代码..





Hi slightly modified your code..


class Program
   {
       static void Main(string[] args)
       {


           int i, num;
           num = 5;
           for (i = 1; i <= num; i++)  // iterates till the num count
           {

               for (int left = 1; left < i; left++)
               {
                   System.Console.Write(left); // prints the left side value
               }
               for (int right = i; right >= 1; right--)
               {
                   System.Console.Write(right); // prints the right side value
               }
               Console.WriteLine();
           }

           Console.ReadLine();

       }
   }







它会产生一种模式如下所示:

1

121

12321

1234321

123454321 < br $>




它做什么:

它会将中间数字增加1,然后它会打印出来双方的数字直到1

* 左侧:减1并打印到1

* 右侧:递增1并打印至1



num 表示必须打印图案的结束计数。




It will produce a pattern like the below:
1
121
12321
1234321
123454321


What it does:
It will increment the middle number by 1, and then it will print the numbers till 1 on both the side
* Left Side : decrement by 1 and print till 1
* Right Side : increment by 1 and print till 1

num denotes the ending count, to which the pattern has to be printed.


这篇关于我想快速解释一下这段代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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