2013-01-14 46 views
-2

我寫了下面的程序:迴歸方法,計算錯誤

public double calcElectricityCO2(double avgBill,           double avgPrice) 
    { 
     return (avgBill/avgPrice)*1.37*12; 

    } 
    public static void main(String[ ] args) 
    { 
     double avgBill = 338.59; 
     double avgPrice = 0.12; 
     double emmision = calcElectricityCO2(avgBill,avgPrice); 
     System.out.printf("Annual CO2 Emission from Electricity Usage: %1.2f %n",emmision); 
    }  
} 

當運行在double emmision = calcElectricityCO2(avgBill,avgPrice);報告錯誤,我做了什麼錯在那裏?

+9

_錯誤是什麼意思?_ – SLaks

回答

8

您的calcElectricityCO2應宣佈爲static

public *static* double calcElectricityCO2(double avgBill, double avgPrice){ 
    //implementation 
} 
+0

非常感謝您的幫助。 – user1928899

+1

不客氣。正如上面提到的SLak,如果包含錯誤(如果使用Eclipse或IntelliJ,請將鼠標懸停在冗長的紅色線條上)會更好。此外,接受滿意的答案是一種好的做法。 –