我想編寫一個計算複合利息的方法。這是我不斷收到的錯誤消息:編寫一個計算合併利息的方法
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;
}
}
精氨酸。我盯着那麼久。謝謝。 – user2918429