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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply