首页 > 试题广场 >

(驾驶费用)编写一个程序,提示用户输人驾驶的距离、以每加仑

[问答题]
 (驾驶费用)编写一个程序,提示用户输人驾驶的距离、以每加仑多少英里的汽车燃油性能,以 及每加仑的价格,然后显示旅程的费用。下面是一个运行示例:

package com.jinling.day01;
import java.util.Scanner;

public class NKTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the driving distance: ");
        double distance = sc.nextDouble();
        System.out.print("Enter miles per gallon: ");
        double milesPerGallon = sc.nextDouble();
        System.out.print("Enter price per gallon: ");
        double pricePerGallon = sc.nextDouble();
        sc.close();
//        使用该方法保留两位小数String.format(format,ags)
        System.out.print("The cost of driving is $" + String.format("%.2f", distance / milesPerGallon * pricePerGallon));
    }
}
发表于 2021-05-02 09:27:25 回复(0)
公式是啥啊?要我们自己推吗?
发表于 2021-04-08 14:03:14 回复(0)
public  int[] 

发表于 2019-11-09 07:59:59 回复(0)