# String[][] - How to

• 12-04-2012, 07:01 PM
eddierwalker
String[][] - How to
Hi. This is my first post here.

My problem is next.

I have created a matrix ( String [4][3] ) like this:

A B C

D E F

G H I

J K L

... and I want to search in it the next matrix:

E F

H I

... and I have no clues how to do it.

Any help is appreciated. ^_^
• 12-04-2012, 07:04 PM
Fubarable
Re: String[][] - How to
If this were my assignment, I'd simplify it first and figure out how to solve this with a 1 dimensional array. Once done it wouldn't be hard to extend that solution to a 2D array.
• 12-04-2012, 08:07 PM
DarrylBurke
Re: String[][] - How to
• 12-05-2012, 01:23 PM
eddierwalker
Re: String[][] - How to
Quote:

Originally Posted by Fubarable
If this were my assignment, I'd simplify it first and figure out how to solve this with a 1 dimensional array. Once done it wouldn't be hard to extend that solution to a 2D array.

I tried every solution I found on internet but I'm always receiving this error: EXPECTED Array, FOUND String[][].

Code:

```import java.util.*; import java.io.*; public class Diagrama{     public static void main (String[] args) {         int row, column;         OnlyUpperCase alfa = new OnlyUpperCase(); //  boolean classes with corresponding procedures         OneCharOnly beta = new OneCharOnly();    //  I am not writing them here because         OnlyNumbers gama = new OnlyNumbers();  //  it's easy to figure out what they perform.         String matrix[][] = new String[13][20];         String wordToBeFound[];         String a, b;         Scanner scan = new Scanner(System.in);                 System.out.println ("Only UPPER-CASE characters:");                                       for (row=0; row < 13; row++ )         for (column=0; column < 20; column++) {               System.out.println ("Element " + row + " " + column);               a=scan.nextLine();               while (!alfa.containsOnlyUpperCase (a) ||  !beta.containsOnlyOneChar (a)){                         System.out.println ("One char only!");                         a=scan.nextLine();                         }                         matrix[row][column]=a;               }                                          for (row=0; row < 13; row++ ) {                       System.out.println ("");                 for (column=0; column < 20; column++)                             System.out.print (" " + matrix[row][column]); }                       System.out.println ("Word length (MIN 3, MAX 20):");                       b=scan.nextLine();                       while (!gama.containsOnlyNumbers (b) || Integer.parseInt( b )>20 || Integer.parseInt( b )<3){                                       System.out.println ("Erorr! Number of letters between 3 and 20!");                                                    b=scan.nextLine();                                       }                       wordToBeFound=new String[Integer.parseInt( b )];                           System.out.println ("One UPPER-CASE char at a time:");                                                for (row=0; row < wordToBeFound.length; row++ ){                               System.out.println (row+1 + " letter: "); // It start default with 0 but I want to start with 1                               a=scan.nextLine();                               while (!alfa.containsOnlyUpperCase (a) ||  !beta.containsOnlyOneChar (a)){                                       System.out.println ("Only single UPPER-CASE chars allowed!");                                       a=scan.nextLine();                               }                                                                                wordToBeFound[row]=a;                       }             } }```

I know it's a mess. Have a bit of mercy for me! ^_^

So ... I want to find wordToBeFound in matrix.
• 12-05-2012, 01:52 PM
Tolls
Re: String[][] - How to
When you get an error you need to post the full description and highlight the location in your code it occurs on.

And you do need to sort out indenting your code properly.
It will help you immensely in that you can actually follow the flow of the code just by looking at it.