首页 > 试题广场 >

(金融:比较成本)假设你要通过两种不同的包裹运输大米。你将

[问答题]
 (金融:比较成本)假设你要通过两种不同的包裹运输大米。你将乐于编写一个程序来比较成本, 该程序提示用户输入每个包裹的重童和价格,然后显示具有更好价格的包裹。下面是一个运行 示例:


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入第一包大米的重量和价格:");
        double weight1 = sc.nextDouble();
        double price1 =sc.nextDouble();
        System.out.print("请输入第二包大米的重量和价格:");
        double weight2 =sc.nextDouble();
        double price2 =sc.nextDouble();
        sc.close();
        double isprice = price1/weight1 - price2/weight2 ;
        if (isprice == 0){
            System.out.println("两包大米价格一样");
        }else if(isprice >0 ){
            System.out.println("第二包大米价格更实惠");
        }else{
            System.out.println("第一包大米价格更实惠");
        }
    }
编辑于 2021-05-04 16:23:49 回复(0)
System.out.println("请分别输入包裹一和包裹二的重量以及价格");
        Scanner scanner=new Scanner(System.in);
        double weight1=scanner.nextDouble();
        double price1=scanner.nextDouble();
        double weight2=scanner.nextDouble();
        double price2=scanner.nextDouble();
        if(weight1/price1>weight2/price2) {
            System.out.println("包裹二有着更好的价格");
        }else if (weight1/price1==weight2/price2) {
            System.out.println("两个包裹有着同样的价格");
        }else {
            System.out.println("包裹一有着更好的价格");
        }
       
发表于 2019-11-01 10:40:41 回复(0)