-
array problem
I have a strig array of nine elements say
String temp[] = {"1", "2", "3", "4", "5", "6", "7", "8", "0"};
I want to break this in to a double dimensional array
like
int[][] puz = { { 1, 2, 3 }, { 4, 5, 6 }, { 7,8, 0 } };
I am getting :rolleyes:
please help me
-
So what you actualy want to do is convert the String array that you have into a two dimensional integer array?
-
-
What i probably would do is loop through the string array that you have and invoke the Integer.parseInt(String s) method.
-
how's this? :)
Code:
String temp[] = {"1", "2", "3", "4", "5", "6", "7", "8", "0"};
int [] [] td = new int [3] [3];
for (int i = 0; i < 3; i++)
for (int j = 0; j , 3; j++)
td [i] [j] = Integer.parseInt ( temp [j+(i*3)]);
that should do it, though there might be an error inside those for loops... oh well =D!