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.
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
881 /usr/bin/google-chrome:symbol lookup error:/usr/bin/google-chrome: undefined symbol:gbm_bo_get_modifier
578 Understanding How to Configure Google API Key
1022 In Java servlet, when SHA-256 sends WW-Authenticate header for digest authentication, the client does not return the result.
© 2024 OneMinuteCode. All rights reserved.