Advertisement
Jgug

1D array to 2d array

Nov 7th, 2014
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. public int[][] getInt2DArray(String str) {
  2.     String[] arrStr  = str.split(" ");
  3.     int arrLength = arrStr.length;
  4.     int size = (int) Math.sqrt(arrLength);
  5.     int[][] arrInt = new int[size][size];
  6.     for (int i = 0; i < size; i++) {
  7.         for (int j = 0; j < size; j++) {
  8.             arrInt[i][j] = Integer.parseInt(arrStr[j+i*size]);
  9.         }
  10.     }
  11.     return arrInt;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement