JAVA问题:一个程序能换算美金单位

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:59:16
一个程序,能输入几美金几美分,然后程序输出刚才输入的钱是由多少dollar,quarter,dime,nickels,penny组成的。1dollar=100cents;1quarter=25cents;1dime=10cents;1nickels=5cents;1penny=1cents

public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
System.out.println("输入美元数");
int dollars = sca.nextInt();
System.out.println("输入美分数");
int cents = sca.nextInt();
int all = dollars * 100 + cents;
System.out.println(all / 100 + "dollars" + all % 100 / 25 + "quarter"
+ all % 25 / 10 + "dimes" + all % 10 / 5 + "nickets" + all % 5
+ "cents");
}