-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpg.java
More file actions
23 lines (19 loc) · 728 Bytes
/
Copy pathmpg.java
File metadata and controls
23 lines (19 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package Java;
import java.util.Scanner;
public class mpg {
public static void main(String args[]) {
// clear unnecessary output in Terminal
System.out.print("\033[H\033[2J");
System.out.flush();
System.out.println("Please enter your car consumption in l/100km:");
double input;
Scanner sc = new Scanner(System.in);
input = sc.nextDouble();
double mpgfactor = 235.215;
double output = (mpgfactor/input);
// format the output
String result = String.format("%.4g", output);
System.out.println("Your consumption of " + input + " l/100km equals an endurance of " + result + " miles per gallon.");
sc.close();
}
}