我是Java新手。我收到了「非法開始表達錯誤」。我一直在尋找答案,並找不到,如果我使用括號不正確,但我已經嘗試了它沒有括號,並與他們似乎並沒有得到通過這1錯誤。我可以使用一些幫助。 謝謝:)在Java中非法啓動表達式
public class LIANGLAB1
{
public static void main(String[] argv){
gasStation A = new gasStation(3.39, 3.49);
gasStation B = new gasStation(3.19, 3.39);
A.sellregular(10); A.sellregular(10);
B.sellregular(11); B.sellregular(12);
if (A.moreprofit(B)) System.out.println("station A is more profitable");
else System.out.println("station B is more profitable");
gasStation G[] = new gasStation[10];
for(int i=0;i<10;i++) G[i] = new gasStation(3.19,3.39);
{gasStation highest =G[0];}
for (int i=1;i<10;i++)
{if (G[i].moreprofit(highest)) highest = G[i];
{System.out.println("highest total sales is" +highest.sales+);}
//ERROR IS HERE
}
}
}
class gasStation
{
double regularprice;
double superprice;
double sales;
public gasStation(double r, double s)
{regularprice = r; superprice = s; sales = 0;}
public void sellregular(double gallons)
{sales += regularprice * gallons;}
public void sellsuper(double gallons)
{sales += superprice * gallons;}
public void gouge()
{superprice *= 2; regularprice *=2;}
public boolean moreprofit(gasStation other)
{return sales > other.sales;}
}
'highest.sales +);}'...刪除最後的加號。並請:使用正確的縮進和換行符。它有助於可讀性。擁有一個包含(和普遍接受的)編碼風格有助於可讀性,不僅適用於您自己,而且對於查看您的代碼的其他人也尤其如此。 – 2014-09-04 19:26:09
這段代碼有很多錯誤,很難知道從哪裏開始。錯誤從上到下。 – duffymo 2014-09-04 19:26:52
這是我見過的最古怪的括號風格。 – Kayaman 2014-09-04 19:27:31