This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.

Randall Twede wrote:i think i figured it out maybe. i am using longs so the % operator rounds results?

Not sure what you mean by that, but whatever you mean, no that's not it.

Why does that output surprise you? What would you expect instead? You should add print statements or use a debugger so you can see what's actually happening?

Also note that when checking for divisors of X, you only need to go up to the square root of X.

ok, i solved that one. now i am trying to solve problem3 a projectEuler.net
here is my solution of original problem

the new problem is this: What is the largest prime factor of the number 600851475143 ?
even using longs the number is too big. and Math.sqrt() requires a double and the number is too big

600851475143 does fit in a long, but if you write it in source code you have to put an "L" at the end of it: long value = 600851475143L;

If you don't, Java is going to interpret 600851475143 as an int literal instead of a long, and it's going to tell you the number is too big to fit in an int.

To solve this problem, you should do something smarter than checking if all numbers smaller than 600851475143 are primes. That's the trick of this Project Euler exercise!