fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. public static int[] expand(int[][] src, int blockWidth, int blockHeight) {
  12.  
  13. if (src == null || src.length == 0) {
  14. return new int[0];
  15. }
  16.  
  17. int span = src[0].length * blockWidth;
  18. int[] dest = new int[src.length * blockHeight * span];
  19. for (int i = 0; i < dest.length; i++) {
  20. dest[i] = src[(i / span) / blockHeight][(i % span) / blockWidth];
  21. }
  22. return dest;
  23. }
  24.  
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. int[][] src = {
  28. {1,2},{3,4}
  29. };
  30. int[] dest = expand(src, 4, 2);
  31. System.out.println(Arrays.toString(dest));
  32. }
  33. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
[1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4]