Page 1 of 1

Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and outp

Posted: Tue Jul 12, 2022 8:17 am
by answerhappygod
Driving is expensive. Write a program with a car's miles/gallonand gas dollars/gallon (both doubles) as input, and output the gascost for 20 miles, 75 miles, and 500 miles.
Output each floating-point value with two digits after thedecimal point, which can be achieved as follows:System.out.printf("%.2f", yourValue);
The output ends with a newline.
Ex: If the input is:
the output is:
Note: Real per-mile cost would also include maintenance anddepreciation.