⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 breaksum.java

📁 此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码。
💻 JAVA
字号:
// BreakSum.java: Break down an amount into smaller units
public class BreakSum
{
  // Main method
  public static void main(String[] args)
  {
    double amount; // Amount entered from the keyboard

    // Receive the amount entered from the keyboard
    System.out.println(
      "Enter an amount in integer, for example 11.56");
    amount = MyInput.readDouble();

    int remainingAmount = (int)(amount*100);

    // Find the number of one dollars
    int numOfOneDollars = remainingAmount/100;
    remainingAmount = remainingAmount%100;

    // Find the number of quaters in the remaining amount
    int numOfQuarters = remainingAmount/25;
    remainingAmount = remainingAmount%25;

    // Find the number of dimes in the remaining amount
    int numOfDimes = remainingAmount/10;
    remainingAmount = remainingAmount%10;

    // Find the number of nickels in the remaining amount
    int numOfNickels = remainingAmount/5;
    remainingAmount = remainingAmount%5;

    // Find the number of pennies in the remaining amount
    int numOfPennies = remainingAmount;

    // Display results
    System.out.println("Your amount " + amount + " consists of ");
    System.out.println("  " + numOfOneDollars + " dollars");
    System.out.println("  " + numOfQuarters + " quarters");
    System.out.println("  " + numOfDimes + " dimes");
    System.out.println("  " + numOfNickels + " nickels");
    System.out.println("  " + numOfPennies + " pennies");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -