缺少格式参数异常

时间:2015-01-12 22:56:55

标签: java arrays null

编译时我得到一个" java.util.MissingFormatArgumentException:null(在java.util.Formater中)我不知道为什么。

"Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier 's'"

请帮助。

 import java.lang.*;
 import java.util.Random;
 import java.util.Scanner;

 import static java.lang.System.out;

 public class DartSimV1
 {


static double[] SiXX(int Money)
{
    double[] VarXX;
    VarXX = new double[Money];

    int IBS;
    IBS = 0;
    if (IBS < VarXX.length) {
        do {
            VarXX[IBS] = Math.random();
            IBS++;
        } while (IBS < VarXX.length);
    }
    return VarXX;
}

public static double[] SiYY(int Money)
{
    double[] VarYY;
    VarYY = new double[Money];

    int IBS;
    IBS = 0;
    while (true) {
        if (false) {
            break;
        }
        if (!(IBS < VarYY.length)) {
            break;
        }
        VarYY[IBS]=Math.random();
        IBS++;
    }

    return VarYY;
}



public static double WhatPie(double[] IBS,double[] YYCoord)
{
    double [] VarXX;
    VarXX = IBS;
    double [] VarYY;
    VarYY = YYCoord;
    double Totals;
    Totals = 0;
    double Contacts;
    Contacts = 0;

    int IBO;
    IBO = 0;
    if (IBO < VarXX.length) {

        if ((Math.pow(VarXX[IBO], 2) + Math.pow(VarYY[IBO], 2)) <= 1) {
            Totals++;
            Contacts++;
        } else Totals++;
        IBO++;
        if (IBO < VarXX.length) {
            do {

                if ((Math.pow(VarXX[IBO], 2) + Math.pow(VarYY[IBO], 2)) <= 1) {
                    Totals++;
                    Contacts++;
                } else {
                    Totals++;
                }
                IBO++;
            } while (IBO < VarXX.length);
        }
    }

    double PIE;
    PIE = 4 *
            (Contacts
                    /
                    Totals);

    return PIE;
}

public static void Answers(int Done, double New)
{
    double PIE;
    PIE = New;

    System.out.printf("Trial [" + Done +"]: PIE = %11.3f%s",PIE);
}

public static void PieA(double[] New, int Done)
{
    double[] PIE;
    PIE = New;
    int trials;
    trials = Done;
    double Totals;
    Totals = 0.0;

    int i;
    i = 0;
    if (i < PIE.length) {
        double IBS;
        IBS = PIE[i];
        Totals += IBS;
        i++;
        if (i < PIE.length) {
            do {

                IBS = PIE[i];
                Totals += IBS;
                i++;
            } while (i < PIE.length);
        }
    }
    double PieA;
    PieA = Totals/trials;
    System.out.printf("AVG for π = %11.3f%s",PieA);


}

public static void main(String[] args)
{


    Scanner show;
    show = new Scanner(System.in);

    System.out.print("# per trials?: ");
    int dPt;
    dPt = show.nextInt();
    System.out.print("Trial #'s?: ");
    int nTri;
    nTri = show.nextInt();

    double[] PieA;
    PieA = new double[nTri];

    int IBS=0;
    while (IBS<nTri) {
        double [] VarXX;
        VarXX = SiXX(dPt);
        double [] VarYY;
        VarYY = SiYY(dPt);
        double PIE;
        PIE = WhatPie(VarXX,VarYY);
        PieA[IBS]=PIE;
        Answers(IBS,PIE);

        IBS++;
    }

    PieA(PieA,nTri);


}

}

1 个答案:

答案 0 :(得分:3)

System.out.printf("Trial [" + Done +"]: PIE = %11.3f%s",PIE);有2个参数:一个浮点%11.3f和一个字符串%s。您只提供了一个值来打印PIE。它需要两个 - 一个浮点数和一个字符串。

另外:该例外为您提供问题的完整详细信息 - 包括行号。你应该在你的问题中加入这个,以便给人们最好的回答机会。