Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java, please. I've given myself a headache. 1.30 LAB: Driving costs Driving is expensive. Write a program with a cars miles/gallon and gas dollars/gallon (both
Java, please. I've given myself a headache.
1.30 LAB: Driving costs Driving is expensive. Write a program with a cars miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Qutput each floating-point value with two digits after the decimal point, which can be achieved as follows: System. out. printf("\%.2f", yourvalue); The output ends with a newline. Ex: If the input is: 20.03.1599 the output is: 3.1811.8579.00 Note: Tee permile cost wou d also include mantenance and depreciation. import java.util.Scanner; public class LabProgram \{ public static void main(String[] args) \{ Scanner obj = new Scanner(System.in); double car_mile =obj.nextDouble(); double dolitar = obj.nextDouble(); double twenty_miles =( dollar*20.0)/car_mile; double seventyfive_miles =( dollar*75.0)/car_mile; double fivehundred_miles =( dollar*500.0)/car_mile; System.out.printf("\%.2f \%.2f \%.2f", twenty_miles, seventyfive_miles, fivehundred_miles); \} Output is nearly correct, but whitespace differs. See highlights below. Input Your output Expected output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started