BigInteger sum = BigInteger.valueOf(0); for(int i = 2; i < 5000; i++) { if (isPrim(i)) { sum.add(BigInteger.valueOf(i)); } }
I wrote it like this. The value of sum is always 0. Is there something wrong?
BigInteger is imutable, so the value does not change. Therefore, the sum value does not change. You should reallocate the value of sum in the add method.
sum = sum.add(BigInteger.valueOf(i));
Like this.
539 Understanding How to Configure Google API Key
543 Who developed the "avformat-59.dll" that comes with FFmpeg?
538 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
538 PHP ssh2_scp_send fails to send files as intended
593 /usr/bin/google-chrome:symbol lookup error:/usr/bin/google-chrome: undefined symbol:gbm_bo_get_modifier
© 2024 OneMinuteCode. All rights reserved.