3.7(金融应用:整钱兑零)修改程序清单2-10,使之只显示非零的币值单位,用单词的单数形式显示一个单位,例如1dollar and 1 penny(1美元和1美分);用单词的复数形式显示多于一个单位的值,例如2dollars and 3 pennies(2美元和3美分)。
3.7(Financial application: monetary units) Modify Listing 2.10, ComputeChange.java, to display the nonzero denominations only, using singular words for single units such as 1 dollar and 1 penny, and plural words for more than one unit such as 2 dollars and 3 pennies.
下面是参考答案代码:
import java.util.*;
public class MonetaryUnitsQuestion7 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Receive the amount
System.out.print("Enter an amount in double, for example 11.56: ");
double amount = input.nextDouble();
int remainingAmount &#