Computer Science Canada How do you seach for a string in a 2 dimentional array? |
Author: | rss14 [ Sat Jun 06, 2009 11:48 am ] | ||||
Post subject: | How do you seach for a string in a 2 dimentional array? | ||||
Lets say I want to find the letter "A" in a 2 dimensional array, how can I find what row and column the letter is in? Here is the code:
Mod Edit: Remember to use syntax tags! Thanks ![]()
|
Author: | Zren [ Sat Jun 06, 2009 12:57 pm ] | ||
Post subject: | Re: How do you seach for a string in a 2 dimentional array? | ||
how would you search a one-dimensional array? Think of it as a row. When thinking of a two-dimensional array, look as it as a bunch of rows. Except now you have two variables. So you search each column in the first row, then move to the next row. Search each column in the second row...etc.
Though your kinda looking at a three demensional array if your using Strings instead of characters, but I'll overlook that for now. ![]() |
Author: | rss14 [ Sat Jun 06, 2009 9:20 pm ] |
Post subject: | Re: How do you seach for a string in a 2 dimentional array? |
Yeah I tried that, but it just keeps looping over and over. . . Can you post some sample code? |
Author: | Zren [ Sun Jun 07, 2009 1:49 am ] | ||
Post subject: | Re: How do you seach for a string in a 2 dimentional array? | ||
Weeeeeeeeeeell sure. Can you post your code if your still not getting it though...since your using counted loops, it shouldn't be going into an infinite loop. Btw. Since your using Strings. When your comparing the two, make sure its: string1.contentEquals( string2 ) == true and not string1 == string2 ...otherwise it will look for if the string of data is at the same position in memory, instead of the two strings with the same content.
|