if(weight <= 2)
  {
     charges=miles*1.10;
  }   
  else if(weight > 2 && weight <= 6);
  {
     charges=miles*2.20;
  }
  else if(weight > 6 && weight <= 10);
  {
     charges=miles*3.37;
  }   
  else if(weight > 10 && weight <= 20);
  {
     charges=miles*2.80;   
  }   

This is just part of it but I keep receiving the following error message:

ShippingAssign.java:32: 'else' without 'if'
  else if(weight > 6 && weight <= 10);
  ^
ShippingAssign.java:36: 'else' without 'if'
  else if(weight > 10 && weight <= 20);
  ^
2 errors

----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.

Any idea as in to what I could be doing wrong? I felt like I understood what was being asked of me but clearly I am making a mistake somewhere.

有帮助吗?

解决方案

Remove the ; after every else if.

else if(weight > 2 && weight <= 6);
                ------------------^
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top