我正在尝试编写一种计算复利的方法。这是我不断收到的错误消息:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '.'
at java.util.Formatter.checkText(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at Balance.main(Balance.java:5)
我不太确定从这里去哪里。如果有人能指出我正确的方向,将不胜感激。(System.out.printf("%.2\n", balance(1000.0, .05, 8.5));
作业需要)
public class Balance {
public static void main(String[] args) {
System.out.printf("%.2\n", balance(1000.0, .05, 8.5));
}
public static double balance(double initialBalance, double interestRate,
double years) {
double compoundedInterest = initialBalance * Math.pow(1 + interestRate, years);
return compoundedInterest;
}
}