# Unit 5: Lesson 7: #2 (accelerated help)

**URL:** <https://forum.code.org/t/unit-5-lesson-7-2-accelerated-help/40297>\
**Category:** CSA\
**Tags:** csa-unit-5\
**Created:** [January 14, 2025, 3:58pm UTC](https://forum.code.org/t/unit-5-lesson-7-2-accelerated-help/40297 "2025-01-14T15:58:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff.rhodes](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jeff.rhodes/32/7758_2.png) [@jeff.rhodes](https://forum.code.org/u/jeff.rhodes)\
**Post date:** [January 14, 2025, 3:58pm UTC](https://forum.code.org/t/unit-5-lesson-7-2-accelerated-help/40297/1 "2025-01-14T15:58:42Z")

</div>

I have a student who wants to pass the phrases as a 1D array. We (he) are having trouble doing this, any suggestions???

> **[Code.org](https://studio.code.org/users/sign_in)**
>
> Anyone can learn computer science. Make games, apps and art with code.

---

<div class="post-metadata">

**Author:** ![sam\_stafford](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/sam_stafford/32/7651_2.png) [@sam\_stafford](https://forum.code.org/u/sam_stafford)\
**Post date:** [January 16, 2025, 1:28am UTC](https://forum.code.org/t/unit-5-lesson-7-2-accelerated-help/40297/3 "2025-01-16T01:28:24Z")

</div>

Hi Jeff,

When I click the link you gave it just takes me to [Code.org](http://Code.org)’s landing page and not to a Java Lab project. However, I reworked U5L7 Level 2’s PhraseFinder class to just use a 1D array:

```auto
/*
 * Analyzes phrases and sentences
 */
public class PhraseFinder {

  public static String countPhrases(String[] sentences, String targetPhrase) {
    String result = "";
    
    for (int index = 0; index < sentences.length; index++) {
      int phraseCount = 0;
      
      
        String currentPhrase = sentences[index];
        int location = currentPhrase.indexOf(targetPhrase);

        if (location != -1) {
          phraseCount++;
        }
      

      result += "Index #" + index + ": " + phraseCount + " times\n";
    }

    return result;
  }

  public static String findLongestString(String[][] sentences, String targetPhrase) {
    int longestLength = 0;
    int longestRow = -1;
    int longestCol = -1;
    
    for (int row = 0; row < sentences.length; row++) {
      for (int col = 0; col < sentences[row].length; col++) {
        String currentPhrase = sentences[row][col];
        int location = currentPhrase.indexOf(targetPhrase);

        if (location != -1 && currentPhrase.length() > longestLength) {
          longestLength = currentPhrase.length();
          longestRow = row;
          longestCol = col;
        }
      }
    }

    if (longestRow == -1 && longestCol == -1) {
      return "No string containing the target phrase was found.";
    } else {
      return "The longest string containing the target phrase is \"" + sentences[longestRow][longestCol] +
             "\" at row #" + longestRow + " and col #" + longestCol + ".";
    }
  }
  
}

```

In the main method, you will need to change the code so it reads:

```auto
public class PhraseRunner {
  public static void main(String[] args) {

    // Creates a 2D array of phrases in several sentences
    String[] sentences = { "The quick brown fox", "jumps over the lazy dog", "fox and dog",
                             "Foxes are clever", "but dogs are loyal", "the quick brown fox",
                             "The dog chased the fox", "while the fox jumped", "over the dog" };

    // Calls the countPhrases() method
    System.out.println(PhraseFinder.countPhrases(sentences, "fox"));
    
  }
}

```

Hope this helps!

Best  
-Sam

---

<div class="post-metadata">

**Author:** ![jeff.rhodes](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jeff.rhodes/32/7758_2.png) [@jeff.rhodes](https://forum.code.org/u/jeff.rhodes)\
**Post date:** [January 16, 2025, 4:11pm UTC](https://forum.code.org/t/unit-5-lesson-7-2-accelerated-help/40297/4 "2025-01-16T16:11:30Z")

</div>

You all are the best!!! This was driving me crazy.
