# Thread: String[][] - How to

1. Member
Join Date
Dec 2012
Posts
2
Rep Power
0

## 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. ^_^

2. ## 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.

4. Member
Join Date
Dec 2012
Posts
2
Rep Power
0

## Re: String[][] - How to

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[][].

Java 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.
Last edited by eddierwalker; 12-05-2012 at 05:57 PM.

5. Moderator
Join Date
Apr 2009
Posts
13,315
Rep Power
23

## 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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•