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

📄 taxcalc.java

📁 Beginning Java 2, SDK 1.4 Edition Exercise Code samples for this book
💻 JAVA
字号:
//Chapter 2, Exercise 3 

public class TaxCalc {
  public static void main(String args[]) {
    double income = 87562.34;   
    double taxRate = 0.35;   // 35%  corresponds to 0.35
    double tax = income*taxRate;             
    
    int taxDollars = (int)tax;
    int taxCents = (int)Math.round((tax - taxDollars)*Math.pow(10.0, 2.0)); 

    // Output the results:
    System.out.println("Gross income is $" + (int)income +"."+ (int)Math.round((income - (int)income)*Math.pow(10.0, 2.0)));
    System.out.println("Tax to pay is " + taxDollars + " dollars and "+taxCents+" cents.");

 /*
    The output statements above show how you can put arithmetic expressions as part of the argument
    to the println() method. The compiler takes care of coverting the values that result from the
    arithmetic expressions to a string.
 */
  }
}

⌨️ 快捷键说明

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