#Why my code printed twice

1 messages · Page 1 of 1 (latest)

smoky jackal
#

output is
Pi ≈ 3.1415926408104432225399904
Pi ≈ 3.1415926407501762451465336

Why it gives 2 values

package My.Test;
import java.math.BigDecimal;
import java.math.BigInteger;

public class Pi {
public static void main(String[] args) {
long start = System.currentTimeMillis();
BigDecimal x;
x = BigDecimal.ZERO;

  for (long n = 0;; n++) {
     x = x.add(
           BigDecimal.valueOf(Math.pow(-1, n) / (2 * n + 1))
     );
    
    
     if (System.currentTimeMillis() - start >= 420000) { 
        break;
     }
  }
  System.out.println("Pi ≈ "+ x.multiply(BigDecimal

.valueOf(4)));
}
}

heavy shoalBOT
#

<@&987246399047479336> please have a look, thanks.

proper dust
#

that is a good question

#

you get two prints from running it once?

smoky jackal
#

I am using Java N-IDE on Android is this a big in it ?

#

Or related to code

proper dust
#

well im running it on my computer and it is not printing twice

#

so i don't think the code is the issue

#

something about how you are running it is