Question 2.23

mail@pastecode.io avatar
unknown
java
2 years ago
612 B
2
Indexable
Never
import java.util.Scanner;

public class QuestionTwoPointTwentyThree
{
    public static void main(String[] args) 
    {
         Scanner scanner = new Scanner(System.in);
         System.out.println("Enter the driving distance:");
         double distance = scanner.nextDouble();

         System.out.println("Enter the miles per gallon:");
         double mpg = scanner.nextDouble();
         System.out.println("Enter the price per gallon:");
         double price = scanner.nextDouble();
         double cost = ((distance/mpg)*price);
         System.out.printf("The cost of driving is $ %.2f", cost);
    }
}