title: Recursive Coin Change Making by printing all possible ways
body: <p>I have tried to print all the paths which give the given amount. But my code does not work properly. I think I am missing some points to print all possible combinations. For example;</p>
  
  <ul>
  <li>if amount: 7 and startCoin = 25, the program needs to give me:
  {5,1,1} and {1,1,1,1,1,1,1}.</li>
  </ul>
  
  <p>Can you help me to fix these problem?</p>
  
  <p>Note: Preferably Java Solutions   </p>
  
  <pre><code>class Solution {
  
        static int[] coinSet = {1,5,10,25};
        static List&lt;List&lt;Integer&gt;&gt; possibleWays = new ArrayList&lt;&gt;();
        static List&lt;Integer&gt; currentWay = new ArrayList&lt;&gt;();
  
        private static int makeChange(int amount, int startCoin){
  
          boolean flag = false;
          for(int i =0 ; i &lt; coinSet.length ; i++){
            if(coinSet[i] == startCoin) {
              flag =true;
            }
          }
  
          if(!flag){
            throw new IllegalArgumentException("startCoin has to be in the specified range");
          }
  
          int nextCoin = 0;
          switch(startCoin) {
            case 25:
              nextCoin = 10;
              break;
  
            case 10:
              nextCoin = 5;
              break;
  
            case 5:
              nextCoin = 1;
              break;
  
            case 1:
              possibleWays.add(currentWay);
              currentWay = new ArrayList&lt;&gt;();
              return 1;
          }
  
          int ways = 0;
  
          for(int count = 0; count * startCoin &lt;= amount; count++){
            ways += makeChange(amount - (count * startCoin),nextCoin);
          }
  
          return ways;
  
        }    
        public int calculateNumberOfWays(int amount, int startCoin) throws Exception {
          if (amount == 0) {
            throw new Exception();    }
  
          return makeChange(amount, startCoin);
        }
  
        public static void main(String[] args) {
  
          System.out.println(makeChange(5,25));
          System.out.println(possibleWays);
  
        }
      }
  </code></pre>