samedi 28 février 2015

Java Array.Out.Of.Bound exception



I have a huge problem I can not understant why this part of code throws this exception because I can not see where I get out of my array bound? I want to derive a polinom with int coeff and positive powers. i save my powers in an array iPower and my coeff in iCoefficient. in my polinom class iMaxPower gives my the highest fower of my polinom.



public int DerivePolinom(Polinom p1, Polinom p2)//operation class
{
int i,count=0;
i=p1.iMaxPower;

while(i>0)
{
if(p1.iPower[i]==1)// here is my exception!
{
p2.iPower[i]=1;//I know it does not derive my polinom
p2.iCoefficient[i]=p1.iCoefficient[i];
count++;// use this to know the nr of the result polinom terms

}
i++;
}

return count;
}



int iDegreeMax=0;//main class
System.out.print("Enter the polinom: number of terms-power-coefficient \n");
Polinom p1 = new Polinom();//create my polinom object
iDegree=sc.nextInt();//read the numbers of terms
p1.readPolinom(iDegree);//read my polinom
p1.printPolinom(p1,iDegree);

Operation o = new Operation();//create operation object
Polinom p2 = new Polinom();//we create another polinom object to pun the result in
iDegreeMax=o.DerivePolinom(p1,p2);
System.out.print("\nThe derivation of the polinom is: ");
p2.printPolinom(p2,iDegreeMax);



Aucun commentaire:

Enregistrer un commentaire