Click to See Complete Forum and Search --> : array problem
amani
Apr 6th, 2002, 02:11 PM
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
Dillinger4
Apr 6th, 2002, 02:29 PM
So what you actualy want to do is convert the String array that you have into a two dimensional integer array?
amani
Apr 6th, 2002, 02:37 PM
yes you got it right
Dillinger4
Apr 6th, 2002, 02:47 PM
What i probably would do is loop through the string array that you have and invoke the Integer.parseInt(String s) method.
CaptainPinko
Apr 10th, 2002, 04:55 PM
how's this? :)
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!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.