您好,我需要帮助将零钱排序为小数,如 25 美分、便士、镍币等。它说可能有损转换。这是我的代码:
public class Assignment04 {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.println("Enter your amount");
long amount = stdin.nextLong();
long remainder = Math.round(amount * 100 );
long hundreds = (int) remainder / 10000;
remainder = remainder % 10000;
long fifties = (int) remainder / 5000;
remainder = remainder % 5000;
long twenties = (int)remainder / 2000;
remainder = remainder % 2000;
long tens = (int)remainder / 1000;
remainder = remainder % 1000;
long fives = (int)remainder / 500;
remainder = remainder % 500;
long ones = (int)remainder / 100;
remainder = remainder % 100;
long quarters = remainder / .25;
remainder = remainder % .25;
long dimes = (int)remainder / .10;
remainder = remainder % .10;
long nickels = (int)remainder / .5;
remainder = remainder % .5;
double pennies = (int) remainder;
System.out.println(hundreds + "hundred/s");
System.out.println(fifties + "fiftie/s");
System.out.println(twenties + "twentie/s");
System.out.println(tens + "ten/s");
System.out.println(fives + "five/s");
System.out.println(ones + "one/s");
System.out.println(quarters + "quarter/s");
System.out.println(dimes + "dime/s");
System.out.println(nickels + "nickel/s");
System.out.println(pennies + "cent/s");
}
}
我试图弄清楚如何删除红色下划线,以便它可以正确运行。我已经完成了大部分工作,只是当涉及到小数时我感到困惑。
慕标5832272
慕容3067478
不负相思意
相关分类