i code a program in C#, this time i have to write in java and when i tried to add and subtract a simple number such like:
double array1 = new double array1[200];
double array2 = new double array2[200];
for (int var = 1; var < 200; var++)
{
array1[var] = Math.Round(array1[var] + 0.005,3);
array2[var] = Math.Round(1 - array1[var],3);
}
where the output is something like this:
array1[0]=0.005,array1[1]=0.010,array1[2]=0.015,array1[3]=0.020,array1[4]=0.025 ......
array2[0]=1.000,array2[1]=0.995,array2[2]=0.990,array2[3]=0.985,array2[4]=0.980 ......
when i tried to take to java i used the next code:
double array1 = new double[200];
double array2 = new double[200];
for (int var = 1; var < 200; var++)
{
array1[var] = (array1[var] + 0.005);
array2[var] = (1 - array1[var]);
}
the output is the same, after the 6 one because of the imprecision of the double it starts to bring different result, i try to used BigDecimal how ever i still don't understand how to it works or how to add the result inside the array.