GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Programs/CombinationCoinChange.java at main · arshcoder13/Java Expand file tree/ Copy pathCombinationCoinChange.javaMore file actions 54 lines (47 loc) · 1.1 KB / Copy pathCombinationCoinChange.javaFile metadata and controls54 lines (47 loc) · 1.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /*Print all the Combinations of Change for a given Amount*/ class CoinChangeCombination { private static List<Integer> coins; private static int count=0; private static void init() { coins = new ArrayList<Integer>(); coins.add(1); coins.add(3); coins.add(5); coins.add(9); coins.add(10); coins.add(14); coins.add(18); coins.add(23); } /*Prints all comninations of the coin change*/ public static void coinCombinations(int amount,int index,LinkedList<Integer> list) { if(amount==0) { count++; System.out.println(list); return ; } if(amount < 0) return ; for(int i=index ; i < coins.size();i++) { int coin = coins.get(i); if(amount >= coin) { list.add(coin); coinCombinations(amount - coin ,i,list ); list.removeLast(); } } } public static void main(String[] args) { int amount = 175; init(); coinCombinations(amount,0,new LinkedList<Integer>()); //System.out.println("Number of Combinations :" + count); } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |