Error message: "identifier expected"
<p>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.</p>

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

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

<p>I keep getting an error message when I try to compile:</p>

<blockquote>
  <p>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 );<br>
                                  ^ GasolineUsage.java:40: illegal start
  of type
                 System.out.printf( "The car drives %.2f miles pr liter
  gasoline\n\n", milPrLiter );<br>
                                    ^ GasolineUsage.java:40:
   expected
                 System.out.printf( "The car drives %.2f miles pr liter
  gasoline\n\n", milPrLiter );               </p>
  
  <p>^ GasolineUsage.java:42: class, interface, or enum expected }  ^ 5
  errors</p>
</blockquote>

<p>The code is the following:</p>

<pre><code>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 );               
    }
} 
</code></pre>

<p>Can anyone please help me?</p>
