所以基本上,我是 Java 的初学者,我正在学习一门课程。首先,我不明白为什么我在这个程序的开头需要 com.company (使用 IntelliJ IDEA 和 JDK 9.0.1)。其次,我不明白这个程序如何调用“calculateTax”方法,因为唯一的方法调用是在初始化双变量“total”时。这是代码:
package com.company;
public class Main {
public static double subtotal;
// main function of the program
public static void main(String[] args) {
subtotal = 15.00;
System.out.println("Subtotal: " + subtotal);
double total = subtotal + calculateTax(0.08, subtotal);
System.out.println("Total: " + total);
}
public static double calculateTax(double taxRate, double amountToTax) {
double tax = amountToTax * taxRate;
System.out.println("Tax: " + tax);
return tax;
}
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
小计:15.0
税:1.2
总计:16.2进程以退出代码 0 结束 …