// findpi.java // // find pi by using // the old random number trick // // import java.math.*; public class findpi extends Object { public static void main( String[] a) { double in,out; int i; in = 0; out = 0.; while( out < 1.e7) { double x,y; for(i=0; i< 10000; i++) { x = Math.random(); y = Math.random(); x = x*x + y*y; out += 1.; if( x < 1.) in += 1.; } System.out.println( "Pi 3.14159265 "+ in/out*4. +" at "+out+" Tries"); } // here does x or y mean anything? } }