user2918429
user2918429

Reputation: 53

Writing a method that computes compunded interest

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

Answers (3)

Ashish
Ashish

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

Rahul
Rahul

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

Masudul
Masudul

Reputation: 21961

You missed f for floating format. Try System.out.printf("%.2f\n",balance(1000.0, .05, 8.5));

Upvotes: 1

Related Questions