Exception in Thread "Main" Java. Util. Unknownformatconversionexception: Conversion = '-'

The problem is "Conversion = '-'". The source code is here, I had commented the "printf" to avoid some problems, always cased by "print": this is a program used for calculating Loan in year.

import java.util.*;
public class Loan{
    public static void main(String args[]){
        final double MIN = 0.05;
        final double MAX = 0.08;
        final double ADD = 0.125;
        Scanner input = new Scanner(System.in);
        System.out.print("Loan Amount: ");
        double amount = input.nextDouble();
        System.out.print("Number of Years :");
        int years = input.nextInt();
        /*  
        for(double r = MIN; r < MAX;r = r + ADD){
          double R = Math.pow((1+r),years);
          double monthlyPayment = r * R * amount / 12/(R-1);
          double totalPayment = 12*monthlyPayment*years;
          System.out.printf("%-20s%-20s%-20\n","InterestRate","MonthlyPayment","TotalPayment");
          System.out.printf("%%-20f%-20.2f%-20.2f\n",r,monthlyPayment,totalPayment);
         }
         */     
     }
}
2

3 Answers

You're missing a format specifier character, replace

System.out.printf("%-20s%-20s%-20", "InterestRate", ...)

with

System.out.printf("%-20s%-20s%-20s", "InterestRate", ...
                                 ^
0

I Guess you want this,

System.out.printf("%-20s%-20s%-20s", "InterestRate",
        "MonthlyPayment", "TotalPayment\n");
System.out.printf("%-20.2f%-20.2f%-20.2f\n", r, monthlyPayment,
        totalPayment);

Use below code it will work

System.out.printf("%-20s %-20s %20s %n","InterestRate","Monthly Payment","Total Payment\n");               
System.out.printf("%-20f %-20.2f %-20.2f\n",r,monthlyPayment,totalPayment);

Let me know if anything else required

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest