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 7580061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:49:21+00:00 2026-05-30T17:49:21+00:00

I’m coding a wordsearch puzzle and I need to write a helper method called

  • 0

I’m coding a wordsearch puzzle and I need to write a helper method called isHorizontalSpaceFree().

The method should check whether (starting from aRow and aCol) there is enough free space to insert word into letterGrid(left to right). If there is enough space, the method should return true, otherwise it should return false.

I need the method to return an out of bounds exception if the word length exceeds the end of the array as well.

Here is my code so far

   public boolean isHorizontalSpaceFree(int aRow, int aCol, String word)
   {
      boolean result = true;
      if (aCol < NUMBER_COLS - word.length())
      {
        int i = aCol;
        while (aCol < NUMBER_COLS - word.length())
        {
          if (letterGrid[aRow][aCol] != BLANK_ELEMENT
              || aCol > NUMBER_COLS - word.length())
          {
            result = false;
          }
          aCol++;
        }
      }
      else
      {
        result = false;
      }
      return result;
    }

I hope it’s not too far away.

  • 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-30T17:49:22+00:00Added an answer on May 30, 2026 at 5:49 pm

    Based on your code, I’m assuming you want the method to return true if:

    1. There are enough remaining columns between aCol and NUMBER_COL to fit the word
    2. Each of cells in aRow between aCol and aCol + word.length() are BLANK_ELEMENTs

    Given the above, the following should work:

    public boolean isHorizontalSpaceFree(final int aRow, final int aCol, final String word) {
        // Asserts that the word will fit in the remaining cells
        if(aCol + word.length() > NUMBER_COLS) {
            return false;
        }
        // Asserts that each cell in the row aRow between aCol and aCol+word.length() are empty
        char[] columns = letterGrid[aRow] // I've assume your grid is made up of chars
        for(int i = aCol; i < aCol + word.length(); i++) {
            if(columns[i] != BLANK_ELEMENT) {
                return false;
            }
        }
        // There is enough remaining blank cells to insert the word
        return true;
    }
    

    Edit: As mentioned in Andreas_D answer, this method shouldn’t really be throwing an exception, rather returning just true and false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
In my XML file chapters tag has more chapter tag.i need to display chapters

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.