// Calculating PI by iterative approximation // Using Math.class (no import needed) import java.io.*; class iteration { public static void main (String[] args) throws IOException { BufferedReader stdin; stdin = new BufferedReader (new InputStreamReader (System.in)); System.out.print ("Enter accuracy: "); double epsilon = (Double.valueOf (stdin.readLine())).doubleValue(); int n = 4; double s, c, inner = 2.0, outer = 4.0; c = 1 / Math.sqrt(2); while (outer-inner > epsilon) { System.out.println (n + "\t" + inner + "\t" + outer); n = n * 2; s = Math.sqrt((1 - c) / 2); c = Math.sqrt((1 + c) / 2); inner = n * s * c; outer = n * s / c; } } }