import java.text.DecimalFormat;

public class ABC_Polynom {


// Bestimme die Summe von 1 bis n
public void test1() {
double xa = 0.0;
double xsw = 0.4;
double xe= 12.0;
calcPolynom(xa,xsw,xe,new double[]{1, 2});  // y=2x+1    a0 a1
calcPolynom(xa,xsw,xe,new double[]{1, 2, 3}); // a0 a1 a2  y=3x² + 2x + 1
}

private double power(double x, int n) {
double p = 1.0;
for (int i = 0; i < n; i++) {
p *= x;
}
return p;
}

private void calcPolynom(double xa,double xsw,double xe,double[] coeff) {
double x=xa;
DecimalFormat df = new DecimalFormat("0.000");
System.out.println("x"+"\t"+"y");
while (x<=xe+xsw*0.2) {
// das laufende x ist gegeben
// gesucht f(x) mit Hilfe der Polynom Koeffizienten
double y=0;
for (int i=0; i<coeff.length; i++) {
y +=  coeff[i] *  power(x,i);
}
System.out.println(df.format(x)+"\t"+df.format(y));
x+=xsw;
} // while
System.out.println();
System.out.println();
}

public static void main(String[] args) {
ABC_Polynom instance = new ABC_Polynom();
instance.test1();
}
}