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.
1028 Error in x, y, and format string must not be None
1038 M2 Mac fails to install rbenv install 3.1.3 due to errors
1586 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
1070 Uncaught (inpromise) Error on Electron: An object could not be cloned
1118 /usr/bin/google-chrome:symbol lookup error:/usr/bin/google-chrome: undefined symbol:gbm_bo_get_modifier
© 2025 OneMinuteCode. All rights reserved.