问题
public class Problem3 {
public static void main (String args[]) {
System.out.print(primeMod(60085147514L));
}
public static double primeMod(long d) {
long max = 0;
int count = 0;
for (long i = 2; i < d; i++) {
if (d % i == 0) {
boolean isPrime = primeCounter(i);
if(isPrime == true) {
max = i;
System.out.println(max);
}
} else {
max = max;
}
}
return max;
}
public static boolean primeCounter(long x) {
int count = 0;
for (int s = 1; s <= x; s++) {
if (x % s == 0) {
count++;
}
}
if (count == 2) {
return true;
} else {
return false;
}
}
}
My program works for smaller numbers but it Throws an Arthmetic Exception for Divide by 0 when its not dividing by zero.please dont give me the answer,just wanna understand it and improve my skills thank you
回答1:
My guess would be that s
is overflowing, leading eventually to a divide by zero. Make s
a long
instead.
来源:https://stackoverflow.com/questions/12611149/project-euler-3-java