Java Array Max Value max(float[] v1, float[] v2)

Here you can find the source of max(float[] v1, float[] v2)

Description

max

License

Open Source License

Parameter

Parameter Description
v1 a parameter
v2 a parameter

Declaration

public static float[] max(float[] v1, float[] v2) 

Method Source Code

//package com.java2s;
/**//from  w  ww .j  a va2s. co m
   Copyright (c) 2014, the LESK-WSD-DSM AUTHORS.
    
   All rights reserved.
    
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are
   met:
    
 * Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
    
 * Redistributions in binary form must reproduce the above
   copyright notice, this list of conditions and the following
   disclaimer in the documentation and/or other materials provided
   with the distribution.
    
 * Neither the name of the University of Bari nor the names
   of its contributors may be used to endorse or promote products
   derived from this software without specific prior written
   permission.
    
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
   GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007
 **/

public class Main {
    /**
     *
     * @param v1
     * @param v2
     * @return
     */
    public static float[] max(float[] v1, float[] v2) {
        float[] v = new float[v1.length];
        for (int i = 0; i < v1.length; i++) {
            if (v1[i] >= v2[i]) {
                v[i] = v1[i];
            } else {
                v[i] = v2[i];
            }
        }
        return v;
    }

    /**
     *
     * @param v1
     * @param v2
     * @return
     */
    public static double[] max(double[] v1, double[] v2) {
        double[] v = new double[v1.length];
        for (int i = 0; i < v1.length; i++) {
            if (v1[i] >= v2[i]) {
                v[i] = v1[i];
            } else {
                v[i] = v2[i];
            }
        }
        return v;
    }
}

Related

  1. max(float... values)
  2. max(float[] floats)
  3. max(float[] in, int[] idx)
  4. max(float[] position, int x)
  5. max(float[] t)
  6. max(int array[])
  7. max(int value1, int value2, int... values)
  8. max(int... _is)
  9. max(int... args)