每当我尝试调用我的任何构造函数时,我都会不断收到空指针执行
public class Poly{
private static class Pair{
int coeff;
int exponent;
}
int count=1;
private Pair[] poly =new Pair[count];
public Poly(){
poly = new Pair[count];
poly[count-1].coeff=0;
poly[count-1].exponent=0;
count++;
}
public Poly(int coeff1, int exp){
poly = new Pair[count];
//poly.add(new Poly(coeff1, exp));
poly[count-1].coeff=coeff1;
poly[count-1].exponent=exp;
count++;
}
private Poly (int exp) {
poly = new Pair[exp+1];
poly[0].exponent = exp;
}
public String toString(){
String str ="";
for(int i=0; i<=count; i++){
str+= poly[i].coeff +"x^" +poly[i].exponent;
}
return str;
}
public static void main(String[] args) {
Poly p =new Poly(5, 3);
System.out.println(p.toString());
}
}