Help with java code.

Caporegime
Joined
12 Mar 2004
Posts
29,962
Location
England
My java program won't compile and as usual the compiler gives a useless error message.

Code:
class galltolit
{
public static void main(String[] args)
{
double gallons;
double litres;
gallons = 10;
litres = gallons*4.6;
System.out.println(gallons+" gallons is "+litres+" litres ");
for(litres;litres<50;litres++)
System.out.println(litres);
System.out.println("done");
}}

Code:
galltolit.java:10: not a statement
for(litres;litres<50;litres++)
    ^
1 error
 
Last edited:
JIMA said:
Hi,

Try setting the initialization of the loop to be:

for (litres=litres;litres<50;litres++)

It would probably be better coding though to have another variable for your loop though so the loop leaves the original litres value as it was when the loop was entered.

Hope that helps.
Jim


Thanks. :)
 
Back
Top Bottom