Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4232056
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:02:48+00:00 2026-05-21T02:02:48+00:00

I’m completely lost. I’ve googled for this problem for possibly 30 minutes now, and

  • 0

I’m completely lost. I’ve googled for this problem for possibly 30 minutes now, and I can’t find any java specific solutions (or any solutions that crossover into java).

I’ve tried using the generic two simple for loops for going through each individual String, but it only seems to return results if the search term is in the first column of the array.

    public static String search(String term) {
        String result = "";
        int row = db.bookdb.length;

        for (int i=0; i<db.bookdb.length; i++) {
            for (int j=0; j<4; j++) {
                if (term.equals(db.bookdb[i][j])) {
                     row = i;
                     break;
                }
            }
        }

        if (row == db.bookdb.length) {
            result += "Your search failed to return any results";
        }
        else {
            for (int j=0; j<4; j++) {
                result += db.bookdb[row][j] + "    ";
            }
        }

        return result;
    }

db is the object i’m working with, and bookdb is the 2D array within said object. (and yes, the amount of columns will always be 4)

If there’s any additional information you guys need feel free to ask.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:02:49+00:00Added an answer on May 21, 2026 at 2:02 am

    Your search method works fine. I created a class and used your Search method (COPIED AND PASTED, I didn’t even change your search) and it works. This leads me to believe the problem is in how you’re entering your data.

    class Pdeuchler {
    
        static Pdeuchler db;
    
        String[][] bookdb;
    
    
        public static String search(String term) {
            String result = "";
            int row = db.bookdb.length;
    
            outer_loop: // CHANGE #1 added a named loop
            for (int i=0; i<db.bookdb.length; i++) {
                for (int j=0; j<4; j++) {
                    if (term.equals(db.bookdb[i][j])) {
                         row = i;
                         //break; //REMOVED
                         break outer_loop; // CHANGE #2 breaking to the outer_loop
                    }
                }
            }
    
            if (row == db.bookdb.length) {
                result += "Your search failed to return any results";
            }
            else {
                for (int j=0; j<4; j++) {
                    result += db.bookdb[row][j] + "    ";
                }
            }
    
            return result;
        }
    
        public static void main(String[] args) {
            db = new Pdeuchler();
            db.bookdb = new String[10][4]; // title, author, publisher, year
    
            db.bookdb[0] = new String[] {"Awesome Book","Stan","West","2001"};
            db.bookdb[1] = new String[] {"Cool Story","Dan","North","2002"};
            db.bookdb[2] = new String[] {"Brothers","North","North","2003"};
            db.bookdb[3] = new String[] {"Never again!","Bob","West","2004"};
            db.bookdb[4] = new String[] {"Howdy Partner","Stan","South","2005"};
            db.bookdb[5] = new String[] {"What the StackOverflow?","Dan","North","2006"};
            db.bookdb[6] = new String[] {"That's hilarious","Angie","South","2007"};
            db.bookdb[7] = new String[] {"I like pie","Angie","East","2008"};
            db.bookdb[8] = new String[] {"Bob writes a book","Bob","South","2009"};
            db.bookdb[9] = new String[] {"The adverntures of Bob","Bob","North","2010"};
    
            System.out.println(search("I like pie"));
            System.out.println(search("North"));
            System.out.println(search("Dan"));
        }
    
    }
    

    And the results:

    C:\junk>java Pdeuchler
    I like pie    Angie    East    2008
    The adverntures of Bob    Bob    North    2010
    What the StackOverflow?    Dan    North    2006
    
    C:\junk>
    

    and the results with the change:

    C:\junk>javac Pdeuchler.java
    
    C:\junk>java Pdeuchler
    I like pie    Angie    East    2008
    Cool Story    Dan    North    2002
    Cool Story    Dan    North    2002
    
    C:\junk>
    

    If we use an advanced search method (which I’m calling search2) we get this:

    C:\junk>java Pdeuchler
    simple search:
    I like pie    Angie    East    2008
    Cool Story    Dan    North    2002
    Cool Story    Dan    North    2002
    
    advanced search:
    I like pie    Angie    East    2008
    
    Cool Story    Dan    North    2002
    Brothers    North    North    2003
    What the StackOverflow?    Dan    North    2006
    The adverntures of Bob    Bob    North    2010
    
    Cool Story    Dan    North    2002
    What the StackOverflow?    Dan    North    2006
    
    
    C:\junk>
    

    Here’s the advanced search method:

    public static String search2(String term) {
        String result = "";
        int row = db.bookdb.length;
    
        for (int i=0; i<db.bookdb.length; i++) {
            for (int j=0; j<4; j++) {
                if (term.equals(db.bookdb[i][j])) {
                     row = i;
                     for (int k=0; k<4; k++) {
                         result += db.bookdb[i][k] + "    ";
                     }
                     result += "\n";
                     break; // breaks out of the INNER (j) loop
                }
            }
        }
    
        if (row == db.bookdb.length) {
            result += "Your search failed to return any results";
        }
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.