Loop Adding BigInteger java -
this question has answer here:
- java: how use biginteger? 9 answers
i've got array of bigintegers, , want add them 1 biginteger. i've used method.add(), reason, sum remains 0.
biginteger[] numbers = { new biginteger("20849603980134001723930671666823555245252804609722"), . . . new biginteger("53503534226472524250874054075591789781264330331690") }; biginteger sum = new biginteger("0"); for(int = 0; < numbers.length; i++) { sum.add(numbers[i]); system.out.println(numbers[i]); system.out.println(sum); } system.out.println(sum);
thank help!
biginteger
immutable - calling sum.add(...)
nothing sum
returns new biginteger
.
so need change code to:
sum = sum.add(numbers[i]);
Comments
Post a Comment