我無法找到所寫的內容。我正在嘗試Project Euler#16,在那裏我需要總計2^1000的所有數字。我的程序使用小數字,但數字大約在18位左右,因此打破了。任何幫助?回答問題中的未知因素
public static double digit(double n){
return n % 10;
}
public static double sumofDigits(double n){
double sum = 0;
while(n > 1){
sum += digit(n);
n = Math.floor(n/10);
}
return sum;
}
public static void main(String[] args) {
double x = Math.pow(2,1000);
double y = 22222222222222222222d;
System.out.println(sumofDigits(x));
System.out.println(sumofDigits(y));
}
}
「it break」是什麼意思?你有錯誤嗎?它是什麼? – Ben