import java.util.*;
import java.lang.*;
/**
* To answer the question "How many combinations of coins add up to $1.00". US
* currency is assumed. Reptition is assumed. Does not calculate permutations
* where position is important.
**/
class Main
{
public static int PENNY = 1;
public static int NICKEL = 5;
public static int DIME = 10;
public static int QUARTER = 25;
public static int HALF = 50;
private int combinations = 0;
{
Main main = new Main();
main.run();
}
private void run(){
// iterate through each coin and add up the combinations
// pennies
int current = 0;
for(int i = 0; i <= 100; i++){ // pennies
current = i * PENNY;
for(int j = 0; j <= 20; j++){ // nickels
current = current + (j * NICKEL);
for(int k = 0; k <= 10; k++){ // dimes
current = current + (k * DIME);
for(int m = 0; m <= 4; m++){ // quarters
current = current + (m * QUARTER);
for(int n = 0; n <= 2; n++){ // halves
current = current + (n * HALF);
if(current == 100){
combinations++; // increment combination count
}
current = 0; // start again
}
}
}
}
}
System.
out.
println("There are " + combinations
+ " possible combinations."); }
}