Java Array Divide divisors(final int n, final int[] buffer)

Here you can find the source of divisors(final int n, final int[] buffer)

Description

divisors

License

EUPL

Parameter

Parameter Description
n a parameter
buffer a parameter

Declaration

public static int divisors(final int n, final int[] buffer) 

Method Source Code

//package com.java2s;
/*/*from w w w.  j a  v  a 2s.  c o  m*/
* Copyright 2013 National Bank of Belgium
*
* Licensed under the EUPL, Version 1.1 or ? as soon they will be approved 
* by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software 
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and 
* limitations under the Licence.
*/

public class Main {
    /**
     * 
     * @param n
     * @return
     */
    public static int[] divisors(final int n) {
        int[] tmp = new int[1 + n / 2];
        int nd = divisors(n, tmp);
        int[] rslt = new int[nd];
        for (int i = 0; i < nd; ++i)
            rslt[i] = tmp[i];
        return rslt;
    }

    /**
     * 
     * @param n
     * @param buffer
     * @return
     */
    public static int divisors(final int n, final int[] buffer) {
        if (n == 1)
            return 0;
        int d = 1;
        int idx = 0;
        while (d * 2 <= n) {
            if (n % d == 0)
                buffer[idx++] = d;
            ++d;
        }
        return idx;
    }
}

Related

  1. divideInPlace(float[] vector, float val)
  2. divideIntoChunks(Object[] objs, int chunkSize)
  3. divideNonSingular(int[] array1, int[] array2)
  4. divideVector(float[] resultVec, float divisor)
  5. divideVectors(float[] v1, float[] v2)
  6. divVec2(final float[] result, final float[] vector, final float scale)