Last active
May 23, 2016 22:37
-
-
Save hamedrnik/993eaba7760e89f6dc2219149a5cb1f3 to your computer and use it in GitHub Desktop.
Convert 1D array into 3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.converter; | |
import java.util.Arrays; | |
import java.util.regex.Matcher; | |
public class tset39 { | |
public static void main(String[] args) { | |
int width = 2; | |
int height = 2; | |
int depth = 2; | |
int[] rr1 = {1, 2, 3, 4, 5, 6, 7, 8}; | |
System.out.println(Arrays.deepToString(tset39.arrst(rr1, width, height, depth))); | |
} | |
public static int[][][] arrst(int[] a, int width, int height, int depth) | |
{ | |
int array3[][][] = new int[width][height][depth]; | |
for (int x = 0; x < width; x++) { | |
for (int y = 0; y < height; y++) { | |
for (int z = 0; z < depth; z++) { | |
array3[x][y][z] = a[height * depth * x + depth * y + z]; | |
} | |
} | |
} | |
return array3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment