#java.lang.ArrayIndexOutOfBoundsException: 0

1 messages · Page 1 of 1 (latest)

raw bough
#

In this line it is produces the error:

Pol= new double[f];
for(f=0;f<PX;f++){
Pol[f]=scan.nextDouble();
}

PX is an arbitrary double.

inner oxideBOT
#

<@&987246399047479336> please have a look, thanks.

calm plume
#

why are you reusing a variable for the for loop?

#

also please share the real code

#

what is f?

#

it seems to be 0 when creating the array

raw bough
#

private Scanner teclado=new Scanner(System.in);
private int PX;
private double DV;
private double DVN;
private double LogX;
private double LogXN;
private double Pol[];
private double PolX[];
private double X1[];
private double R1[];
private double R2[];
private int f;

public void Divisores(){
    System.out.println("Ingresar grado:");
    PX=teclado.nextInt();
    System.out.println("Ingresar posible divisor:");
    DV=teclado.nextDouble();
    if(DV<0){
      DVN=DV*-1;  
    }
    LogX=Log(PX,DVN);
    LogXN=LogX*-1;
    System.out.println(LogX);
}

public static double Log(double PX, double DV){
 return (Math.log(DV)/Math.log(PX));   
}

public void Polinomio(){
    Pol= new double[f];
    PolX= new double[f];
    System.out.println("Polinomio");
    double X=PX;
    for(f=0;f<PX;f++){
        X=X-1;
        System.out.println("Ingresar término:");
        Pol[f]=teclado.nextDouble();
         if(X!=0){
          PolX[f]=X;
        }
    }
    X=PX;
    System.out.println("Expresión actual:");
    System.out.print("X^"+PX+" "+DV+":( ");
    for(f=0;f<PX;f++){
    X=X-1;
    if(X!=0){
      System.out.print(Pol[f]);
    System.out.print("X^"+PolX[f]+" ");  
    }else{
       System.out.print(Pol[f]);
    }
    }
     System.out.print(" )");
}
calm plume
#

yeah f is 0