1、源代码
package packg;
import java.util.Scanner;
/**
* 秦九韶算法
*
* @author bear
*
*/
public class qinjiushao {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = 0;
System.out.print("请输入n的值: ");
n = input.nextInt();
double x = 0;
System.out.print("请输入x的值: ");
x = input.nextDouble();
double a[] = new double[n + 1];
for (int i = 0; i <= a.length - 1; i++) {
System.out.print("请输入a" + i + "的值: ");
a[i] = input.nextDouble();
}
double v = 0;
if (n == 0) {
v = a[n];
} else {
for (int i = 0; i <= a.length-1; i++) {
v = v * x + a[i];
}
}
System.out.println("多项式的值为:"+v);
}
}
评论0