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;
}
}
}我的程序适用于较小的数字,但是当它不被zero.please除以时,它抛出一个被0除的算术异常不要给我答案,只是想理解它并提高我的技能谢谢
发布于 2012-09-27 06:23:42
我的猜测是,s正在溢出,最终导致除以零。改为将s设置为long。
https://stackoverflow.com/questions/12611149
复制相似问题