Copy an array of signed values in int, into an array of double. Sign extension is performed. - Java java.lang

Java examples for java.lang:int Array

Description

Copy an array of signed values in int, into an array of double. Sign extension is performed.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int[] src = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(java.util.Arrays
                .toString(copySignedIntToDoubleArray(src)));
    }/*from   w w  w . ja  v  a 2  s  . com*/

    /**
     * <p>Copy an array of signed values in int, into an array of double.</p>
     *
     * <p>Sign extension is performed.</p>
     *
     * @param   src   an array of int, whose values are interpreted as signed
     * @return      an array of double
     */
    static public double[] copySignedIntToDoubleArray(int[] src) {
        if (src == null)
            return null;
        int n = src.length;
        double[] dst = new double[n];
        for (int j = 0; j < n; ++j) {
            dst[j] = src[j]; // allow sign extension
        }
        return dst;
    }
}

Related Tutorials