title: Unique Ways To Give Change- Not Outputting Expected Values
body: <p>I'm trying to create a program that outputs all the possible unique ways to make change for a given input using ONLY recursion and constant memory(so no loops).</p>
  
  <p>For an amount of 25 cents it should print out all possible combinations in the following example format:</p>
  
  <pre><code>0*25+0*10+1*5+20*1
  0*25+0*10+2*5+15*1
  etc..
  </code></pre>
  
  <p>Where 0* is the number of quarters(25) used as an example</p>
  
  <p>The problem with my program is that it only prints out:</p>
  
  <pre><code>0=0*25+0*10+0*5+25*1+
  </code></pre>
  
  <p>and not the rest of the combinations. I suspect this is due to me messing up the printCombinations and getLargerCombinations methods (which are basically recursive methods that simulate a for loop), but I can't figure out what the problem is.</p>
  
  <p>Here is the whole code:</p>
  
  <pre><code>public class HW {
  
      static int[] coins = {25,10,5,1};
      static int[] counts = new int[coins.length];
  
  
      static void getCombinations(int[] counts, int startIndex, int totalAmount) {
          if(startIndex&gt;= coins.length) {
              System.out.print(""+totalAmount+"=");
              printCombinations(0);
              return;
          }
  
          if(startIndex == coins.length - 1) {
  
              if(totalAmount%coins[startIndex]==0) //good combo 
              {
                  //setting count of coins at start index
                  counts[startIndex] = totalAmount/coins[startIndex];
                  //move on to recursive calls
                  getCombinations(counts, startIndex + 1, 0);
              }
          }
  
          else //still need to choose 0-N larger coins
          {
              getLargerCoins(0, totalAmount, startIndex);
  
          }
  
  
      }
  
      //Prints out all the possible combinations of change
      static void printCombinations(int i) {
          if(i &gt;= coins.length) {
              System.out.print("\n");
              return;
          }
          System.out.print("" + counts[i] + "*" + coins[i] + "+");
          printCombinations(++i);
      }
  
  
  
      static void getLargerCoins(int j, int totalAmount, int startIndex) {
          if(j &gt;= totalAmount/coins[startIndex]) {
              return;
          }
          //for every cycle in the loop, we choose an arbitray # of larger coins and proceed next
          counts[startIndex] = j;
          getCombinations(counts, startIndex+1, totalAmount-coins[startIndex]*j);
          j++;
      }
  
      public static void main(String[] args) {
          getCombinations(counts, 0, 25);
      }
  
  
  
  }
  </code></pre>
  
  <p>****EDIT:*****</p>
  
  <p>Under the getLargerCoins method I just iterated j++ but forgot to call the getLargerCoins method to continue the recursion. Fixed the line by writing:</p>
  
  <pre><code>getLargerCoins(++j, totalAmount, startIndex);
  </code></pre>
  
  <p>Output when running the program:</p>
  
  <pre><code>0=0*25+0*10+0*5+25*1+
  0=0*25+0*10+1*5+20*1+
  0=0*25+0*10+2*5+15*1+
  0=0*25+0*10+3*5+10*1+
  0=0*25+0*10+4*5+5*1+
  0=0*25+1*10+0*5+15*1+
  0=0*25+1*10+1*5+10*1+
  0=0*25+1*10+2*5+5*1+
  </code></pre>
  
  <p>However, it is still not outputting all the possible combinations</p>