How can I calculate minimum, maximum and average using Java?
Assuming you have data values in a Java storage structure, the key part of the process is to iterate through the values, check and store the minimum and maximum values, the running total and number of data points. Lets take the simple case of an iterator over a set of DataPoint objects that have an int getValue() method. This example has int variables for max, min, count, sum and a temporary dataValue. The initial value for max is set to Integer.MIN_VALUE so that any given value should exceed it, and min is set to Integer.MAX_VALUE. A float type is specified for the mean variable since integer division is likely to result in a fraction and the decimal part should be preserved. … full answer hidden, click here for all answers Actions: Follow-up or correct this answer. Submit a new question.