2015-01-12 3 views
-2

: (java.util.Formater에서) 널 (null)을 모르겠어요 왜누락 된 형식 인수는 예외

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


} 
..

}

답변

2

System.out.printf("Trial [" + Done +"]: PIE = %11.3f%s",PIE); 2 개 매개 변수가 있습니다. 하나의 플로트 %11.3f 한 문자열 %s를에만 PIE를 인쇄 할 그것을 하나 개의 값을 부여했습니다. 그것은 두 개가 필요합니다 - 부유물과 문자열.

또한 예외 : 줄 번호를 포함하여 문제의 전체 세부 정보를 제공합니다. 사람들에게 답변 할 수있는 기회를주기 위해 질문에 포함시켜야합니다.

+0

어디에서 두 번째 문자열을 추가해야합니까? 어떻게 추가해야합니까? – bhsingh

+0

'System.out.printf ("시험판"+ 완료 + "] : PIE = % 11.3f % s", PIE, "내 문자열!");' –

관련 문제