Calculate prime numbers in Java