我正在製作一個程序,將一個大數字變成一個字符串,然後添加該字符串的字符。它工作正常,我唯一的問題是,它不是將它作爲一個正常的數字,而是將Java轉換爲標準形式,這使得解析字符串變得困難。有沒有解決這個問題的方法?任何方式來避免包含結果「9.223372036854776E18」
public static void main(String ags[]) {
long nq = (long) Math.pow(2l, 1000l);
long result = 0;
String tempQuestion = Double.toString(nq);
System.out.println(tempQuestion);
String question = tempQuestion.substring(0, tempQuestion.length() - 2);
for (int count = 0; count < question.length(); count++) {
String stringResult = question.substring(count, count + 1);
result += Double.parseDouble(stringResult);
}
System.out.println(result);
你的代碼是什麼? –
你的情況是什麼將是一個'正常'的數字? –