克服java.util.MissingFormatArgumentException

时间:2014-12-06 20:39:34

标签: java

我目前正在尝试完成一个项目,以确定投资率等等,为期5年,利率从2.5开始。我继续在第22行用java.util.MissingFormatArgumentException绊倒:空。

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

1 个答案:

答案 0 :(得分:0)

System.out.printf("%6s %6.2f\n", term);

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