C# 试图解决Euler#1项目的问题
我在尝试制作一个小应用程序来解决问题时遇到了问题 每当我尝试运行它时,它返回为0,而不是233168 我不一定要寻找一个绝对的答案,只是一些提示,我正在努力学习C# 试图解决Euler#1项目的问题,c#,C#,我在尝试制作一个小应用程序来解决问题时遇到了问题 每当我尝试运行它时,它返回为0,而不是233168 我不一定要寻找一个绝对的答案,只是一些提示,我正在努力学习 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(s
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();
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
命名空间控制台应用程序1
{
班级计划
{
静态void Main(字符串[]参数)
{
int x;
List listOne=新列表();
对于(x=1;x<1000;++x)
{
如果(x%3==0 | | x%5==0)
{
添加(x);
}
Console.WriteLine(listOne.Sum());
Console.ReadLine();
}
}
}
}
为了帮助您学习,我不会给出确切的答案
查看
控制台.WriteLine()语句的作用域。我猜它没有在你认为应该的时候运行。哇,你说得对,我不知道我是怎么看的。非常感谢。现在返回的数字太大了,但我会尝试找出其中一个。@MD.Unicorn哈哈,对不起,我不是要覆盖您的格式编辑。当你把你的文件放进去的时候,我正在编辑中:/我会把它放进一个新的。我真的很抱歉格式不好,我会在下一篇文章中记住这一点。谢谢你的提示@user2264393没有那么糟糕,我们只是在为将来可能也会遇到问题的人整理它#1:)没有正确格式化代码将导致这样的错误。