Java Array Multiply mult(float[] nums, float n)

Here you can find the source of mult(float[] nums, float n)

Description

mult

License

Apache License

Declaration

public static float[] mult(float[] nums, float n) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

public class Main {
    public static float[] mult(float[] nums, float n) {
        assert !Float.isInfinite(n) : "Trying to multiply "
                + Arrays.toString(nums) + " by  " + n; // Almost surely not what you want
        for (int i = 0; i < nums.length; i++)
            nums[i] *= n;/*  w w  w. j  a  va  2 s  .  c om*/
        return nums;
    }

    public static double[] mult(double[] nums, double n) {
        assert !Double.isInfinite(n) : "Trying to multiply "
                + Arrays.toString(nums) + " by  " + n; // Almost surely not what you want
        for (int i = 0; i < nums.length; i++)
            nums[i] *= n;
        return nums;
    }

    public static double[][] mult(double[][] ary, double n) {
        if (ary == null)
            return null;
        for (int i = 0; i < ary.length; i++)
            mult(ary[i], n);
        return ary;
    }

    public static String[] toString(long[] dom) {
        String[] result = new String[dom.length];
        for (int i = 0; i < dom.length; i++)
            result[i] = String.valueOf(dom[i]);
        return result;
    }

    public static String[] toString(int[] dom) {
        String[] result = new String[dom.length];
        for (int i = 0; i < dom.length; i++)
            result[i] = String.valueOf(dom[i]);
        return result;
    }

    public static String[] toString(Object[] ary) {
        String[] result = new String[ary.length];
        for (int i = 0; i < ary.length; i++) {
            Object o = ary[i];
            if (o != null && o.getClass().isArray()) {
                Class klazz = ary[i].getClass();
                result[i] = byte[].class.equals(klazz) ? Arrays
                        .toString((byte[]) o)
                        : short[].class.equals(klazz) ? Arrays
                                .toString((short[]) o)
                                : int[].class.equals(klazz) ? Arrays
                                        .toString((int[]) o)
                                        : long[].class.equals(klazz) ? Arrays
                                                .toString((long[]) o)
                                                : boolean[].class
                                                        .equals(klazz) ? Arrays
                                                        .toString((boolean[]) o)
                                                        : float[].class
                                                                .equals(klazz) ? Arrays
                                                                .toString((float[]) o)
                                                                : double[].class
                                                                        .equals(klazz) ? Arrays
                                                                        .toString((double[]) o)
                                                                        : Arrays.toString((Object[]) o);

            } else {
                result[i] = String.valueOf(o);
            }
        }
        return result;
    }
}

Related

  1. mult(double[][] A, double[][] B)
  2. mult(float[] nums, float n)
  3. multiply(byte[] a, byte b)
  4. multiply(double factor, double[] vector)
  5. multiply(double[] a, double m)
  6. multiply(double[] a, double v)