Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Compile Errors

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default 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?

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default 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.

Similar Threads

  1. Couple compile errors for dice game
    By smithmar in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2012, 12:16 PM
  2. Replies: 3
    Last Post: March 6th, 2012, 02:50 AM
  3. Remaining compile errors: no suitable method found for & cannot find symbol
    By ChuckLep in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2011, 02:33 PM
  4. Cannot get to compile
    By Goff256 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 19th, 2011, 01:09 PM
  5. Replies: 2
    Last Post: January 7th, 2011, 08:10 PM