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: Help compiling!

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Help compiling!

    Code!

    <public class Lab5a
     
    {
     
     
     
    	Scanner input = new Scanner( System.in);
     
    		int gallons_of_gas = 0;
    		int milesDriven = 0;
    		int tankCounter = 1;
     
    		totalMpg = 0;
     
     
    while ( gallons_of_gas != -999 )
     
     
     
    	System.out.print( "Enter gallons used in filling up the tank or enter -999 to quit: " );
    	gallos_of_gas = input.nextInt();
     
     
    	System.out.print( "Enter miles driven since tank was full: " );
    	milesDriven = Input.nextInt();
     
     
    	System.out.printf( "MPG this tankful: d\n% ", milesDriven / gallons_of_gas );
     
     
     
     
    if (gallons_of_gas = -999 )
     
    	System.out.printf( "Thank you for using the mileage counter 3000, please come again" );
     
     
     
    }

    The errors read as follows:

    < Lab5a.java:35: error: illegal start of expression 
              }
              ^
     
    Lab5a.java:37: error: reached end of file while parsing
    }
      ^
     
    2 errors
    >

    Thanks in advance


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

    Default Re: Help compiling!

    Suggestion number one: reformat your code. Formatting isn't there just to make your code look pretty, it's there to help you debug it at a glance, to see at a glance where blocks begin and where they end, where control structures begin and end, where classes begin and end. Get rid of any extraneous characters, like the < bit at the beginning of your file.

    Next, place all code blocks within curly braces. So all statements within that while loop should go within a set of curly {} braces so that you and the compiler agree on which statements are inside of and which are outside of the loop (you will be surprised to learn that what you think is inside of the loop currently is in fact outside of it.

    Next make sure that all opening curly braces have a matched closing brace. This is where formatting your code well really helps.

    Remember: you can't be sloppy when coding. Each character has purpose, has meaning, so don't use them carelessly.

    Luck!

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Help compiling!

    I will have to work on my formatting. However, I added the {} to what the while statement should encompass, and it still has an error, any other suggestions ? D:

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help compiling!

    it still has an error
    Please copy and paste here the full text of the error message.

    Check that all the {s have a matching }
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. problem with compiling
    By silverpen10 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 21st, 2013, 02:08 PM
  2. Compiling
    By yavo in forum Java Theory & Questions
    Replies: 1
    Last Post: December 24th, 2011, 07:42 AM
  3. Compiling error
    By Bri4n in forum Java Theory & Questions
    Replies: 5
    Last Post: November 7th, 2011, 10:26 PM
  4. Compiling Error?
    By Arkeshen in forum Java Theory & Questions
    Replies: 2
    Last Post: June 22nd, 2011, 04:31 AM
  5. Help with Compiling
    By w.spidey in forum Object Oriented Programming
    Replies: 10
    Last Post: September 9th, 2010, 01:48 PM