线程“main”中的异常 java.util.UnknownFormatConversionException: Conversion = '-'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15245975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:58:11  来源:igfitidea点击:

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '-'

javaimplicit-conversion

提问by vincent

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.

问题是“转换 = '-'”。源代码在这里,我已经注释了“printf”以避免出现一些问题,总是用“print”表示:这是一个用于计算年贷款的程序

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);
         }
         */     
     }
}

回答by Reimeus

You're missing a format specifier character, replace

您缺少格式说明符,请替换

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

with

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

回答by Jayamohan

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);

回答by Ranu Jain

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

如果还有什么需要,请告诉我