克服java.util.MissingFormatArgumentException异常

克服java.util.MissingFormatArgumentException异常,java,Java,我目前正试图完成一个项目,以确定投资利率等5年期限,2.5利率从1000开始。我一直在第22行被一个java.util.MissingFormatArgumentException:null绊倒 import java.util.Scanner; public class midtermpracticeb { public static void main (String [] args) { Scanner in = new Scanner (System.in

我目前正试图完成一个项目,以确定投资利率等5年期限,2.5利率从1000开始。我一直在第22行被一个java.util.MissingFormatArgumentException:null绊倒

import java.util.Scanner;
public class midtermpracticeb
{
    public static void main (String [] args)
    {
        Scanner in = new Scanner (System.in);
        double investment;
        double rateOfReturn;
        int term;

        System.out.print ("What is the value of the initial investment? ");
        investment = in.nextDouble();
        System.out.print ("What is the Rate of Return? ");
        rateOfReturn = in.nextDouble();
        System.out.print ("What is the term of the investment? ");
        term = in.nextInt();

        System.out.printf ("%6s %6s %6s\n", "Year", "Interest", "Balance");
        System.out.printf ("%6s %6s %6s\n", "=====", "=========", "=========");
        for (term = 0; term < 5; term++)
        {
            System.out.printf ("%6s %6.2f\n",term);
            System.out.printf ("%6s %6.2f\n", rateOfReturn);
            double interest = investment * rateOfReturn;
            System.out.printf ("6s %6.2f\n", interest);
            double x = Math.round (investment * 100.0)/100.0;
        }
    }
}
import java.util.Scanner;
公开课中期实习
{
公共静态void main(字符串[]args)
{
扫描仪输入=新扫描仪(系统输入);
双重投资;
双倍回报率;
整数项;
System.out.print(“初始投资的价值是多少?”);
投资=in.nextDouble();
System.out.print(“回报率是多少?”);
返回速率=in.nextDouble();
System.out.print(“投资期限是什么?”);
term=in.nextInt();
System.out.printf(“%6s%6s%6s\n”、“年”、“利息”、“余额”);
System.out.printf(“%6s%6s%6s\n”、“====”、“=======”、“====”、“====”;
用于(术语=0;术语<5;术语++)
{
System.out.printf(“%6s%6.2f\n”,术语);
System.out.printf(“%6s%6.2f\n”,返回率);
双倍利息=投资*回报率;
System.out.printf(“6s%6.2f\n”,利息);
double x=数学四舍五入(投资*100.0)/100.0;
}
}
}

格式字符串有两个参数
%6s
%6.2f
,因此需要给它两个参数。但是您只给出了一个(
term
)。

您的参数数量与格式说明符的数量不匹配。很抱歉,这不是Java问题,而是一个基本的数学问题。e、 g,
System.out.printf(“%6s%6.2f\n”,术语)两个说明符,但一个变量,就是不相加。同样,这只是常识。
System.out.printf("%6s %6.2f\n", term);