
-----------------------------------
rss14
Sat Jun 06, 2009 11:48 am

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: 


import java.util.Scanner; 

public class GPS
{
    // instance variables - replace the example below with your own
    private String userInput; 
    private int colPosition, colWaypoint, rowPosition, rowWaypoint, change, displacement; 
    private String 


Mod Edit: Remember to use syntax tags! Thanks :) Code Here

-----------------------------------
Zren
Sat Jun 06, 2009 12:57 pm

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. ;)

-----------------------------------
rss14
Sat Jun 06, 2009 9:20 pm

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?

-----------------------------------
Zren
Sun Jun 07, 2009 1:49 am

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.


public class Search2DArray {
	public static final int size = 10;

    public static void search( int
