我是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