public class ArchimedesFast { public static void main (String[] argv) { // Radius: double r = 8; // Number of triangles to inscribe. int N = 100; // Interior angle of each. double angle = 2*Math.PI / N; // The corner of the triangle touching the x-axis: double x1 = r; double y1 = 0; // The second corner: double x2 = r * Math.cos (angle); double y2 = r * Math.sin (angle); // Distance between the two: double dist = Math.sqrt ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); // Multiply by N: double perimeter = N * dist; // The estimate of is the perimeter divided by the diameter: double piEstimate = perimeter / (2*r); System.out.println ("pi=" + piEstimate); } }