集册 Java实例教程 将数组乘以固定因子。

将数组乘以固定因子。

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

514
将数组乘以适当的常数。


//package com.nowjava;
/** from 
N o w J a v a . c o m**/


public class Main {

    /**

     * Multiplies the array by a constant factor in place.

     * @param input

     * @param factor

     * @return

     */

    public static void multiply(double[] input, double factor) {

        for (int i = 0; i < input.length; i++) {

            input[i] = input[i] * factor;

        }

    }


    /**

     * Multiplies each value of the first array with the corresponding

     * value of the second one.

     */

    public static double[] multiply(double[] first, double[] second) {

        if (first.length != second.length) {

            throw new IllegalArgumentException("Dimensions don't match! "/** n o w j a v a . c o m - 时代Java 提 供 **/

                    + first.length + " != " + second.length);

        }

        double[] result = new 
展开阅读全文