Results 1 to 5 of 5
  1. #1
    eddierwalker is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Question 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. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

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

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: String[][] - How to

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    eddierwalker is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Default Re: String[][] - How to

    Quote Originally Posted by Fubarable View Post
    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. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Help String Error :[Ljava.lang.String;@121b26b6
    By mathgram8 in forum New To Java
    Replies: 1
    Last Post: 09-13-2012, 07:59 PM
  2. Replies: 3
    Last Post: 02-10-2012, 07:26 PM
  3. Replies: 6
    Last Post: 12-06-2010, 10:26 AM
  4. Replies: 12
    Last Post: 11-26-2010, 09:33 AM
  5. Replies: 1
    Last Post: 11-04-2010, 07:53 PM

Posting Permissions

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