返回方法,计算错误

时间:2013-01-14 21:41:27

标签: java

我写了以下程序:

    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);我在那里做错了什么?

1 个答案:

答案 0 :(得分:8)

您的calcElectricityCO2应声明为static

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