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

4

1 回答 1

8

你的calcElectricityCO2应该被宣布static

 public *static* double calcElectricityCO2(double avgBill, double avgPrice){
    //implementation
 }
于 2013-01-14T21:42:56.703 回答