Instantly share code, notes, and snippets.

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