PP2.10 编写一个程序,确定瓶子里的硬币总面值并以美元和美分为单位打印输出总钱数。读取分别代表25美分、10美分、5美分、1美分硬币数量的整数
注意:在不同的IDE环境下,有部分代码可能需要变更。Java代码中的package和class名称自行设置,本文中采用Test。 IDE工具:IntelliJ IDEA
代码块:
package Test;
import java.util.Scanner;
public class Test {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
int cent25, cent10, cent5, cent1, totalCents, totalDollar;
System.out.print("Enter the amount of 25 cents: ");
cent25 = input.nextInt();
System.out.print("Enter the amount of 10 cents: ");
cent10 = input.nextInt();
System.out.print("Enter the amount of 5 cents: ");
cent5 = input.nextInt();
System.out.print("Enter the amount of 1 cents: ");
cent1 = input.nextInt();
totalCents = cent25 + cent10 + cent5 + cent1;
totalDollar = totalCents / 100;
System.out.println("Total cents = " + totalCents + " cents");
System.out.println("Total Dollars = " + totalDollar + " Dollars " + totalCents%100 + " cents");
}
}



