Reputation: 53
I am trying to write a method that computes compounded interest. This is the error message I keep getting:
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)
I'm not quite sure where to go from here. If anyone could point me in the right direction it would be much appreciated. (The System.out.printf("%.2\n", balance(1000.0, .05, 8.5));
is required by the homework)
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;
}
}
Upvotes: 1
Views: 111
Reputation: 1941
this is what u have written
System.out.printf("%.2\n", balance(1000.0, .05, 8.5));
i think u missed f while writting %.2f
System.out.printf("%.2f\n", balance(1000.0, .05, 8.5));
Upvotes: 0
Reputation: 45060
You forgot to mention the f
to specify the float format there.
System.out.printf("%.2f\n", balance(1000.0, .05, 8.5)); // .2f is the proper syntax
Upvotes: 0
Reputation: 21961
You missed f
for floating format. Try System.out.printf("%.2f\n",balance(1000.0, .05, 8.5));
Upvotes: 1