【发布时间】:2013-11-29 13:06:31
【问题描述】:
我需要增强蛮力多项式评估算法。我收到了 x 的最高幂(n 的值),多项式 (a, b, c, ..) 的所有元素的系数值作为整数数组列表。但是我不能在 java 上应用这个算法: f(x) = ax^n + bx^(n-1) + cx^(n-3)+... + z 我怎样才能在 java 上应用这个多项式?它的算法是什么?有什么帮助吗?
package brute.force;
import java.util.*;
import java.util.Scanner;
public class BruteForce {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
ArrayList<Integer> coefficients = new ArrayList<>();
int powerOfX, x;
System.out.print("Enter integers please ");
System.out.println("(EOF or non-integer to terminate): ");
while(scan.hasNextInt()){
coefficients.add(scan.nextInt());
}
Integer [] nums = coefficients.toArray(new Integer[0]);
for(int i = 0; i < nums.length; i++){
System.out.println(nums[i]);
}
}
}
【问题讨论】:
-
您是在询问算法还是如何在 java 中获取输入。
-
您的具体问题是什么?
-
我在问算法,我得到了上面的所有输入。
标签: java algorithm brute-force