File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Programming-Challenges/Fundamentals
out/production/Programming-Challenges/com/challenges Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments