我想運行Eclipse
下面的代碼作爲Java Application
,它需要主要的方法來定義。在所有試圖做我自己是接收消息:如何定義運行Java程序的主要方法?
方法TemperatureNormalizer()被undefiened該類型TemperatureNormalizer
能否請你幫我把它寫正確?
import java.util.Arrays;
public class TemperatureNormalizer {
private double[] data;
public TemperatureNormalizer(double[] list) {
data = list;
}
public static void main(String[] args) {
TemperatureNormalizer();
}
public double getAdjustedAverage() {
double max = getMax();
double min = getMin();
double sum = getSum();
int insertAt = 0;
for (int i = 0; i < data.length; i++) {
if (data[i] == max || data[i] == min) {
for (int j = i; j > insertAt; j--) {
data[j] = data[j - 1];
}
data = Arrays.copyOf(data, data.length - 1);
}
}
return (sum - max - min)/data.length;
}
public double getMax() {
double current = 0;
for (int i = 0; i < data.length; i++) {
if (data[i] > current) {
current = data[i];
}
}
return current;
}
public double getMin() {
double current = data[0];
for (int i = 0; i < data.length; i++) {
if (data[i] < current) {
current = data[i];
}
}
return current;
}
public double getSum() {
double sum = 0;
for (double d : data) {
sum = sum + d;
}
return sum;
}
}
您需要構建TemperatureNormalizer的實例,因此在主要方法中添加'TemperatureNormalizer temperatureNormalizer = new TemperatureNormalizer();'然後在新行上調用方法'temperatureNormalizer .getAdjustedAverage()' –