<< Google Mars | Home | Happy PI Day >>

Happy PI Day

3.1415926535...

How could one miss this? It's PI day today. Here's a slow converging approximation of PI:

[weiqi@gao] $ cat PI.java
public class PI {
  public static void main(String[] args) {
    double sum = 0.0d;
    for (int i = 1; i < 64000; i++) {
      sum += 6.0/(i*i);
    }
    System.out.println(Math.sqrt(sum));
  }
}
[weiqi@gao] $ javac PI.java
[weiqi@gao] $ java PI
3.1415525815597167
Tags :


Incompressible Java, PI day

Weiqi Gao reminded me that today is “PI Day”; that along wouldn’t warrant a post here, but the Java snippet for estimating the value of PI rather inefficiently, did: [weiqi@gao] $ cat PI.java public class PI { public static void main(...

Add a comment Send a TrackBack