Skip to content

Instantly share code, notes, and snippets.

@bytecodeman bytecodeman/MilesPerGallon.java Secret
Last active Sep 13, 2018

Embed
What would you like to do?
CSC-111 Miles per Gallon program
import java.util.Scanner;
public class MilesPerGallon {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Initial Odometer: ");
double initOdometer = input.nextDouble();
System.out.print("Final Odometer: ");
double finalOdometer = input.nextDouble();
System.out.print("Number of Gallons: ");
double gallons = input.nextDouble();
double mpg = (finalOdometer - initOdometer) / gallons;
System.out.printf("MPG = %f\n", mpg);
input.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.