简体   繁体   English

试图解决Project Euler#1的问题

[英]Issue trying to solve Project Euler #1

I'm having a problem trying to make a small app to solve Project Euler Problem #1 . 我试图制作一个小应用来解决Project Euler问题#1时遇到了问题。

Whenever I attempt to run this, it returns as 0, instead of 233168. 每当我尝试运行它时,它返回0,而不是233168。

I'm not necessarily looking for an absolute answer, just some hints, I'm trying to learn. 我不一定在寻找一个绝对的答案,只是一些提示,我正在努力学习。

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            List<int> listOne = new List<int>();
            for (x = 1; x < 1000; ++x)
            {
                if(x%3 == 0 || x%5 == 0)
                {
                    listOne.Add(x);
                }
                Console.WriteLine(listOne.Sum());
                Console.ReadLine();
            }
        }
    }
}

In the interests of helping you learn, I'm not going to provide the exact answer. 为了帮助你学习,我不打算提供确切的答案。

Have a look at the scoping of your Console.WriteLine() statement. 看看Console.WriteLine()语句的范围。 My guess is that it's not running when you think it should be. 我的猜测是,当你认为它应该是它时它没有运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM