Java - looping in 1 class & adding element to array in another
<p>I have two classes, one running the Main method has the following <code>for</code> loop:  </p>

<pre><code>for (int b = startRecipe; b &lt;= endRecipe; b++)
        {
            Rec = fileScan.nextLine() + "\n";
        }
        System.out.println(theRecipe.addRecipeStep(Rec));
</code></pre>

<p>In my other class, I have the following loop:  </p>

<pre><code> public String[] addRecipeStep(String Rec ){

        for (int a = 0; a &lt; maxNumOfSteps; a++)
            recipeSteps[a] = Rec;

        return recipeSteps;

    }  
</code></pre>

<p><code>int maxNumOfSteps</code> can be accessed across the two classes. My first question is, I would like to loop over the first loop, and for every <code>Rec</code> value, I would like to add it to my <code>recipeSteps</code> array in the second loop. For right now, the second loop only adds the last value that <code>Rec</code> takes, understandably (and the array contains the same thing in all the indices). If I do <code>Rec +=</code> and add every <code>Rec</code> values to 1 index of the array (everything shows up), then it is against the program requirements. Ideally, I should have as many indices in the 2nd array as there are numbers of <code>Rec</code> values.  </p>

<p>Problem # 2 is, when I call the <code>addRecipeStep(param)</code> from the <code>main</code> class, it prints out "trash." I have attempted to use <code>toString()</code> but there has been no successes yet. All advices are welcomed.<br>
Thank you!  </p>
