集册 Java实例教程 对所有数组组件求和,然后加上n的幂。

对所有数组组件求和,然后加上n的幂。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

363
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
对所有阵列组件求和,然后上电n。
//来 自 nowjava.com - 时代Java

//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        double[] data = new double[] { 34.45, 35.45, 36.67, 37.78, 37.0000,

                37.1234, 67.2344, 68.34534, 69.87700 };

        int n = 2;

        System.out.println(getPowerN(data, n));

    }


    /**

     * Sums all components then puts to power n.

     * This is the direct computation of the polynomial expansion

     */

    //also see MathUtils.polynomialExpansion()
    /**
    来 自 NowJava.com
    **/

    public static double getPowerN(double[] data, int n) {

        double ans = 0.0;

      
展开阅读全文