我写了以下程序:
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);
我在那里做错了什么?
答案 0 :(得分:8)
您的calcElectricityCO2
应声明为static
。
public *static* double calcElectricityCO2(double avgBill, double avgPrice){
//implementation
}