Java Array One Dimension to Two Dimension array1DTo2D(int[] array1D)

Here you can find the source of array1DTo2D(int[] array1D)

Description

array D To D

License

Creative Commons License

Declaration

public static int[][] array1DTo2D(int[] array1D) 

Method Source Code

//package com.java2s;
/*//  w  w w.  j  a va2s . c o m
 * Universidad Nacional de Colombia - Sede Bogot? *
 *
 *      Christian Rodriguez - carodriguezb@unal.edu.co
 *
 * C?digo liberado bajo licencia Creative Commons 3.0
 * http://creativecommons.org/licenses/by-nc-sa/3.0/
*/

public class Main {
    public static int[][] array1DTo2D(int[] array1D) {
        int m = (int) Math.sqrt(array1D.length);
        int[][] array2D = new int[m][m];
        for (int x = 0; x < array1D.length; x++) {
            int fila = (x / m);
            int columna = x % m;
            array2D[fila][columna] = array1D[x];
        }
        return array2D;
    }
}

Related

  1. array1DTo2D(double[] In, int H)
  2. array1DTo2D(final Object data, final int bitpix, final int width, final int height)
  3. array1dTo2d(float[] in, int firstDim)
  4. array1Dto2D(int m, int n, double[] b)
  5. array1Dto2D(int[] d1, int imageWidth, int imageHeight)
  6. array2multidim(float[] arr, int width, int height)
  7. ArrayOutOfMultiDimArray(String _sMultiDimArray[][], int _index)