每次運行我的PairTester類時,我都會爲每個結果保留零。誰能告訴我爲什麼?爲什麼我的PairTester類的結果爲零?
public class Pair {
private double val1;
private double val2;
public Pair(double aFirst, double aSecond) {
aFirst = val1;
aSecond = val2;
}
public double getSum() {
double sum = val1 + val2;
return sum;
}
public double getDifference() {
double difference = val1 - val2;
return difference;
}
public double getProduct() {
double product = val1 * val2;
return product;
}
public double getAverage() {
double average = (val1 + val2)/2;
return average;
}
public double getAbsolute() {
double absolute = Math.abs(val1 - val2);
return absolute;
}
public double getMinimum() {
double minimum = Math.min(val1, val2);
return minimum;
}
public double getMaximum() {
double maximum = Math.max(val1, val2);
return maximum;
}
}
這是我的測試類:
public class PairTester {
public static void main(String[] args) {
Pair myPair = new Pair(11, 15);
System.out.println("Sum = " + myPair.getSum());
System.out.println("Difference = " + myPair.getDifference());
System.out.println("Average = " + myPair.getAverage());
System.out.println("Absolute = " + myPair.getAbsolute());
System.out.println("Minimum = " + myPair.getMinimum());
System.out.println("Maximum = " + myPair.getMaximum());
}
}
太謝謝你了!而且我真的認爲我已經明白了......初學者的問題!哈哈! – user2840682