Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8322d17

Browse files
Miles Per Gallon
1 parent d58edcb commit 8322d17

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
A car’s miles-per-gallon (MPG) can be calculated with the following formula:
3+
MPG = Miles driven / Gallons of gas used
4+
Write a program that asks the user for the number of miles driven and the gallons of gas used.
5+
It should calculate the car’s miles-per-gallon and display the result on the screen.
6+
*/
7+
8+
package com.challenges;
9+
10+
import java.util.Scanner;
11+
12+
public class MilesPerGallon {
13+
public static void main(String [] args) {
14+
15+
Scanner scanner = new Scanner(System.in);
16+
17+
// Declare Variables
18+
double miles;
19+
double gallons;
20+
double milesPerGallon;
21+
22+
System.out.println("Please enter the miles: ");
23+
miles = scanner.nextDouble();
24+
25+
System.out.println("Please enter the gallons of gas used: ");
26+
gallons = scanner.nextDouble();
27+
28+
milesPerGallon = miles / gallons;
29+
System.out.println("Miles Per Gallon: " + milesPerGallon);
30+
}
31+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /