你们有这个情况吗,本人是没有

.Net技术 码拜 8年前 (2016-03-03) 765次浏览
问一下本人划下来的1号段子你们有没有中断的情况?就是书上1号段子写的情况!假如有这个情况,你们认为出这本书的老师写的对吗?谢谢
请看代码(求素数):
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ch11Ex03
{
public class Primes
{
private long min;
private long max;
public Primes()
: this(2, 100)
{
}
public Primes(long minimum, long maximum)
{
if (minimum < 2)
min = 2;
else
min = minimum;
max = maximum;
}
public IEnumerator GetEnumerator()
{
for (long possiblePrime = min; possiblePrime <= max; possiblePrime++)
{
bool isPrime = true;
for (long possibleFactor = 2; possibleFactor <= (long)Math.Floor(Math.Sqrt(possiblePrime)); possibleFactor++)
{
long remainderAfterDivision = possiblePrime % possibleFactor;
if (remainderAfterDivision == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
yield return possiblePrime;
}
}
}
}
class Program
{
static void Main(string[] args)
{
Primes primesFrom2To1000 = new Primes(2,1000);
foreach (long i in primesFrom2To1000)
Console.Write(“{0} “, i);
Console.ReadKey();
}
}
}
请看教材示例说明:
你们有这个情况吗,本人是没有你们有这个情况吗,本人是没有
解决方案

20

而是一遍打印一遍找结果的   –>   而是一边打印一边找结果的
打错一个字,意思就错了哇。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明你们有这个情况吗,本人是没有
喜欢 (0)
[1034331897@qq.com]
分享 (0)