Possible Duplicate:
How to count possible combination for coin problem
In this case suppose the amount is 15 and coins are 1, 6, 7 then total number of ways to it is 6. Below code works fine but its not that much efficient. Any suggestions will be appreciated.
public class CoinProblem {
public static void main(String[] args) {
int amount = 15;
int coinTypes[] = {1,6,7};
int combinations = 0;
for (int i = 0; i * 7 <=15; i++) {
for (int j = 0; j * 6 + i * 7 <= 15; j++) {
combinations++;
}
}
System.out.println(combinations);
}
}