程序未打印所有数字 [英] The program not printing all the numbers

查看:84
本文介绍了程序未打印所有数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C#写了一个简单的代码:

I wrote a simple code in C#:

class Program
  {
      static void Main(string[] args)
      {
          Int64 sum = 8;
          Int64 i;
          for (i = 6; i <= 1000; i++)
          {
              if(i%3==0||i%5==0)
              {
                  sum =sum+i;
                  Console.WriteLine("Sum:" + sum+"   i:" + i);


              }
          }
          Console.WriteLine("Final Sum:"+sum);
          Console.ReadLine();
      }
  }


当我调试它时,它仅从i = 356开始打印.
我更改了for的代码运行到i <= 10为止,然后它很好地打印了数字(当i <= 100时也是如此).
我以前从未遇到过这个问题,它也非常简单,因此我不明白问题出在哪里.


when I debugg it, it start to print only from i=356.
I change the code that the for runs till i<=10, and then it printed well the numbers (also when i<=100).
I never has this problem before, and it also very simple code, so I don''t understand where is the problem.

推荐答案

这不是您的问题程序.只是简单地将可见输出的上一个"行丢弃,然后才能看到它们.您可以增加控制台缓冲区,以便(使用滚动条)查看整个输出.
例如,将以下行添加到您的程序中:
It is not a problem of your program. Simply the ''previous'' lines of the visible output are discarded before you can see them. You could increase the console buffer in order to see (using the scrollbar) the whole output.
For instance, add the following line to your program:
Console.BufferHeight = 3000;


除了CPallini所说的您还可以使用Debug.WriteLine,以便您也可以在调试窗口中查看所有输出.

In addition to what CPallini has said you can also use Debug.WriteLine so that you can see all your output in debug window as well.

class Program
  {
      static void Main(string[] args)
      {
          Int64 sum = 8;
          Int64 i;
          for (i = 6; i <= 1000; i++)
          {
              if(i%3==0||i%5==0)
              {
                  sum =sum+i;
                  Console.WriteLine("Sum:&" + sum+ "     i:" + i);
                  Debug.WriteLine("Sum:"+ sum+"    i:" + i);
              }
          }
          Console.WriteLine("Final Sum:" + sum);
          Debug.WriteLine("Final Sum:" + Sum);
          Console.ReadLine();
      }
  }


这篇关于程序未打印所有数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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