[Bluej-discuss] back to Java
Aryeh M. Friedman
aryeh.friedman at gmail.com
Tue Oct 16 16:40:09 BST 2007
Sounds like the time I learned not to use find all primes under N as an
assignment. Problem:
explaining that if x/y has no remainder then x goes into y evenly.
i.e. all they had to do was:
for(int i=1;i<=n;i++) {
boolean found=false;
for(int j=2;j<n-1;j++) // not worth it to explain you only
need to test odds upto sqrt(n)
if(i%j==0)
found=true;
if(!found)
System.out.println(i);
}
More information about the bluej-discuss
mailing list