fork download
  1. /*Miles per Gallon A car's miles-per-gallon (MPG) can be calculated with the following formula: MPG = Miles driven / Gallons of gas used.
  2.  Write a program that asks the user (or the number of miles driven and the gallons of gas
  3. used. It should calculate the car's miles-per-gallon and display the result on the screen.
  4. */
  5.  
  6. import java.util.Scanner;
  7. public class MilesPerGallon
  8. {
  9. public static void main(String [] args)
  10. {
  11. double milesDriven, gallonsOfGas, milesPer;
  12.  
  13. Scanner driver=new Scanner(System.in);
  14. System.out.println("How many miles did you drive?");
  15. milesDriven=driver.nextDouble();
  16.  
  17. System.out.println("How many gallons of gas was used?");
  18. gallonsOfGas=driver.nextDouble();
  19.  
  20. milesPer=gallonsOfGas/milesDriven;
  21.  
  22. System.out.println("Your vehicles Miles-Per-Gallon is "+milesPer);
  23. }
  24.  
  25.  
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:6:1: error: unknown type name 'import'
import java.util.Scanner;
^
prog.cpp:6:12: error: expected ';' after top level declarator
import java.util.Scanner;
           ^
           ;
prog.cpp:7:1: error: expected unqualified-id
public class MilesPerGallon 
^
3 errors generated.
stdout
Standard output is empty