Question That Needs To Be Solved: http://i62.tinypic.com/23rtieb.png
I have this problem I need to solve using Java. However I tried but was not able to. Here is what I have done so far.
public class Cirlce {
public static void main(String[] args) {
int counter = 0;
double pi = 0;
final String piCharacter = "\u03C0";
double num = 10000;
int e = 0;
for (int i = 0; i < 10000; i++) {
// r^2 = x^2 + y^2
double dx = Math.random();
double dy = Math.random();
double r = Math.sqrt(dx * dx + dy * dy);
if (r < 1) {
counter++;
pi = 4 * counter / 1000;
}
e++;
if (e == counter) {
System.out.println(pi);
counter += 1000;
}
System.out.println("The Approximated Value Of " + piCharacter + " is: " + pi);
}
}
}
The answer is that I need 10 outputs that are close to the value of pi.