0

Here is an example code that I am running. When I place the results in a separate calculator the sum of the array is 344 and upon dividing the sum by the length of the array it shows me 86.

In my other project, this array is placed in other 2D double array which returns decimals (which is correct). Running this in the IDE I get a sum of 344.00...6 and an average of 86.00...1. When compared to another value like 86.5, it displays this average as higher than 86.5.

double sum =0.0;
double average = 0.0;
double [ ] value = {82.2,88.4,88.1,85.3};
for(int c = 0; c< value.length;c++)
{
  sum += value[c];
}
average = sum/value.length;
System.out.println(average);
System.out.println(sum);

Result of code

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Penble
  • 1

0 Answers0