本文介绍了在我的编码中有错误,这可能是从double到int的有损转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! if(unit> = 1&& unit< = 200){ rate = 0.218; } 否则if(unit> = 201&& unit< = 800){ rate = 0.345; } else { rate = 0.421; } 金额= horsePower * 0.746 * rate * numberHours; 金额= sc .nextInt(); System.out.println(支付金额=+金额); 什么我试过了: i试图编译它,但我的计算中仍然有错误。你可以帮助我吗?解决方案 你怎么知道计算中有错误? amount = horsePower * 0 。 746 * rate * numberHours; // 1)在这里你做一些calcylation amount = sc.nextInt(); // 2)在这里用用户输入替换它 System.out.println( 支付金额= +金额); // 3)所以,在这里打印用户输入 if (unit >= 1 && unit <=200){ rate = 0.218; } else if (unit >= 201 && unit <= 800){ rate = 0.345; } else { rate = 0.421; } amount = horsePower*0.746*rate*numberHours; amount = sc.nextInt(); System.out.println ("amount to pay is =" + amount);What I have tried:i have tried to compile it and it still have error in my calculation. Can you help me ? 解决方案How do you know that there is an error in calculation?amount = horsePower*0.746*rate*numberHours; // 1) here you do some calcylationamount = sc.nextInt(); // 2) here you replace it with user inputSystem.out.println ("amount to pay is =" + amount); // 3) so, here you print the user input 这篇关于在我的编码中有错误,这可能是从double到int的有损转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-01 22:28