I have a query ... I have the following code that generates a Pi number of 16 digits ... but I require 20 digits, so I thought it would be convenient to use the bigDecimal but I still do not know how to enter it. help (?
Code:
package io2;
import java.math.BigDecimal;
public class MetodoBuffon {
public static void main(String[] args){
double longitud = 4.4;
double x1;
double x2;
double a;
double b;
double corta= 0;
double total = 100000000;
double n;
for (int i = 0; i < total; i++) {
a= -1 + Math.random() *2;
b = -1 + Math.random() *2;
x1= Math.random();
x2 = x1 +((a* longitud)/ (Math.pow((Math.pow(a, 2)+ Math.pow(b, 2)), 0.5)));
n= 0;
for (int j = 0; j < 1+ (1/longitud); j++) {
if(x1 < n && n< x2){
corta++;
break;
}
if(x1 >n && n> x2){
corta++;
break;
}
n = n + longitud;
}
}
System.out.println("corta: "+corta);
double pi = (2* total)/corta;
System.out.println("pi: "+pi);
}
}