Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6613855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:16:05+00:00 2026-05-25T20:16:05+00:00

I´m doing an exercise from the learning book Java, how to program. I am

  • 0

I´m doing an exercise from the learning book “Java, how to program”. I am supposed to write a program that makes the user type in miles driven, and liters of gasoline used for a not decided number of trips.

The program is supposed to print miles pr liter for each trip, and an average miles pr liter at the end.

I am supposed to use sentinel-controlled repetition, and to print the miles pr liter as floating point values.

I keep getting an error message when I try to compile:

GasolineUsage.java:39: expected
milPrLiter = (double) totalMil / totalLiters;
^ GasolineUsage.java:40:
expected
System.out.printf( “The car drives %.2f miles pr liter
gasoline\n\n”, milPrLiter );
^ GasolineUsage.java:40: illegal start
of type
System.out.printf( “The car drives %.2f miles pr liter
gasoline\n\n”, milPrLiter );
^ GasolineUsage.java:40:
expected
System.out.printf( “The car drives %.2f miles pr liter
gasoline\n\n”, milPrLiter );

^ GasolineUsage.java:42: class, interface, or enum expected } ^ 5
errors

The code is the following:

import java.util.Scanner;
public class GasolineUsage
{

    public static void main( String[] args )
    {    
        int totalMil = 0;
        int totalLiters = 0;
        double milPrLiter1 = 0;
        double milPrLiter;

        Scanner inputMil = new Scanner(System.in);
        Scanner inputLiters = new Scanner( System.in);

        System.out.print( "Type in miles first trip, to end type: -1 " );
            int mil = inputMil.nextInt();
        System.out.print( "Type in liters of gasoline used on first trip " );
            int liters = inputLiters.nextInt();
            totalMil = totalMil + mil; 
            totalLiters = totalLiters + liters;
        milPrLiter1 = (double) mil / liters;
        System.out.printf( "(%.2f miles pr liter this trip.)\n", milPrLiter1 );

        System.out.print( "Type in miles on next trip " );
            while (mil != -1)
                {
                 mil = inputMil.nextInt();
                     if (mil != -1)
                         {totalMil = totalMil+ mil;

                         System.out.print( "Type in lters used on next trip: " );
                         liters = inputLiters.nextInt();}
                         totalLiters = totalLiters + liters;

                         milPrLiter1 = (double) mil / liters;
                         System.out.printf( "(%.2f miles pr liter this trip.)\n", milPrLiter1 );}
                 }

               milPrLiter = (double) totalMil / totalLiters;
               System.out.printf( "The car drives %.2f miles pr liter gasoline\n\n", milPrLiter );               
    }
} 

Can anyone please help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:16:06+00:00Added an answer on May 25, 2026 at 8:16 pm

    Count your opening and closing braces as they should match. You’ve got an extra closing brace hiding in your code that you’ll find if you search for it. Note that with this type of error it’s always good to look above the line that is throwing the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am doing an exercise from Orielly book, and they used that Twitter package
I am a beginner in Java and am doing an exercise from a book.
I'm learning Java and OOPS from oracle's website. I'm doing this exercise . I'm
Today I was doing the thread ring exercise from the Programming Erlang book and
I am learning python atm, and was doing an exercise from this site --
I was doing an exercise on F# Wiki Book on List (scroll to the
Hey all. I'm doing a linked list exercise that involves dynamic memory allocation, pointers,
I'm trying (as a self-learning exercise) to create a Clojure macro that will generate
I'm doing exercise #9 from http://openbookproject.net/thinkcs/python/english2e/ch09.html and have ran into something that doesn't make
I`m doing some exercise on XV6 that is mini OS for education. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.