我是个初学者和我的工作与java目前,我需要写在一个单一的线样的一个公式5x^3+2^4+...使用的内容的节点。
这里是我的类节点:
public class Node {
private Termo element;
private Node next;
public Node(){
element = null;
next= null;
}
public Node( Termo element, Node next){
this.element= element;
this.next= next;
}
public void setnext( Node next){
this.next= next;
}
public Node getnext(){
return proximo;
}
public void setElement( Termo element){
this.element= element;
}
public Termo getElement(){
return element;
}
@Override
public String toString(){
return "Termo: " + getElement().getCoef() + "x^" +getElement().getExp();
}
}
我的课Termo(这是一个目的系数和指数)
private double coef;
private int exp;
public Termo() {
coef=0;
exp=0;
}
public Termo(double coef, int exp) {
this.coef = coef;
this.exp = exp;
}
public double getCoef() {
return coef;
}
public void setCoef(int coef) {
this.coef = coef;
}
public int getExp() {
return exp;
}
public void setExp(int exp) {
this.exp = exp;
}
public Object getObject(){
Termo obj = new Termo(this.coef, this.exp);
return obj;
}
@Override
public String toString() {
return coef + " " + exp;
}
我创造了这个方法的打印内容,但我想在一个单一的线:
public void escrevePolinomio (Node lista){
if(lista != null){
System.out.println(lista.getElement().getCoef()+"x^"+lista.getElement().getExp());
lista=lista.getnext();
escrevePolinomio(lista);
}
}