I have a Java 2d array for numbers, a 10x10 matrix, but how can I go about returning the postioning of a key value (searching for it) and searching for specific positions (using the two coordinates) to put in a value?
Printable View
I have a Java 2d array for numbers, a 10x10 matrix, but how can I go about returning the postioning of a key value (searching for it) and searching for specific positions (using the two coordinates) to put in a value?
might be better if you went to a Java board and asked this :)
But i think what you're asking should work something like this:
then you just do array[3][3] to access the position 4, 4 in the arrayCode:int[][] array=new int[20];
for(int a=0;a<20;a++)
array[a]=new int[20];
or something like that, i haven't coded with Java for a while now (in my java class for my semester test i actually wrote a C++ program, lol)
but yah, like i said, you'll get much better answers from a Java forum :)
i know how to return the pos of a value in a normal 1d array, as it just one integer, but I cant return two numbers for a 2d array...can I?
know any good Java forums?
http://www.google.com/search?hl=en&i...&q=java+forums
should be able to find some good ones there ^^
unlike C++, you can dynamically initialize a multi-dimensional array in java by just specifying the args after new...
ie) .. new int[4][SIZE][otherDynamicVariable];
Hexxx, you seem to have a misconception of what a multi-dimensional array is, you cant return more than one number from it. Its just like a table of single values (2D array that is)