-
Compile Errors
here is my code
public class CarSimulator
{
public static void main(String []args)
{
FuelGauge amountOfFuel = new FuelGauge(0);
Odometer currentMileage = new Odometer(amountOfFuel);
while (FuelGauge.getamountOfFuel < Odometer.getcurrentMileage)
for (FuelGauge.getamountOfFuel < Odometer.getcurrentMileage)
{
System.out.printf("Name = %s\tNumber = %s\n";
}
}
}
here are my compile errors
CarSimulator.java:10: error: > expected
for (FuelGauge.getamountOfFuel < Odometer.getcurrentMileage)
^
CarSimulator.java:10: error: not a statement
for (FuelGauge.getamountOfFuel < Odometer.getcurrentMileage)
^
CarSimulator.java:11: error: illegal start of expression
{
^
CarSimulator.java:11: error: ';' expected
{
^
CarSimulator.java:12: error: illegal start of expression
System.out.printf("Name = %s\tNumber = %s\n";
^
CarSimulator.java:12: error: ')' expected
System.out.printf("Name = %s\tNumber = %s\n";
^
CarSimulator.java:12: error: illegal start of expression
System.out.printf("Name = %s\tNumber = %s\n";
^
CarSimulator.java:12: error: ';' expected
System.out.printf("Name = %s\tNumber = %s\n";
^
CarSimulator.java:12: error: ')' expected
System.out.printf("Name = %s\tNumber = %s\n";
^
CarSimulator.java:12: error: not a statement
System.out.printf("Name = %s\tNumber = %s\n";
^
CarSimulator.java:15: error: class, interface, or enum expected
}
^
11 errors
-
Re: Complie Errors
Your for loop condition is not correct. You'll want to read a decent tutorial on how to create for loops to see how a proper for loop should be written.
But having said this, are you sure that you want to have a for loop nested inside of a while loop? What is your rationale for doing this?
-
Re: Complie Errors
could you show me an example of a loop. and im a beginner java programming so i wasnt aware i had a loop inside a loop. could you help me fix this problem so i have no compile errors.
-
Re: Complie Errors
You can't create loops or write any code until you've figured out the logic of your program. How many loops do you want to do? What will you use to decide when to stop looping? As for showing you code, please check out the Java Tutorials as there are plenty of examples of for, while, and do-while loops to be found there.