算法原理 :
import java.util.Scanner;
public class QinJiuShao {
public static void main(String[] args) {
int n;
double x;
Scanner scan=new Scanner(System.in);
System.out.println("请输入n(表示n次多项式):");
n=scan.nextInt();
System.out.println("请输入x:");
x=scan.nextDouble();
double[] Xishu=new double[n+1];
System.out.printf("请输入%d个系数(a0,a1,a2....an):\n",n+1);
for(int i=0;i<n+1;++i) {
Xishu[i]=scan.nextDouble();
}
double ans=Xishu[n];
for(int i=n-1;i>=0;--i) {
ans=ans*x+Xishu[i];
}
System.out.println(ans);
}
}
请输入n(表示n次多项式):
3
请输入x:
2
请输入4个系数(a0,a1,a2…an):
1 2 3 4
49.0