Hello all. Im taking AP Comp Sci and I'm little stuck on one of the programs we were assigned.
The program basically takes a user input of cents and converts that into all possible combinations of quarters, dimes, nickels and pennies. It then prints out the total number of possible configurations.
Here is what I have so far:
How Many Cents: 6
6 cents = 0 quarters + 0 dimes + 0 nickels + 6 pennies
6 cents = 0 quarters + 0 dimes + 1 nickel + 1 pennies
There are 2 possible ways to make 6 cents using coins.
However, I know this is wrong because it only prints out the combination with the least amount of coins. It is supposed to print ALL possible combinations. Can anyone help?
public class MakeChange
public static void main (String args)
Scanner input = new Scanner(System.in);
System.out.println ("How many cents? ");
int cents = input.nextInt();
int quarters = 0;
int dimes = 0;
int nickels = 0;
int pennies = 0;
while (cents > 0)
if (cents >= 25)
cents -= 25;
else if (cents >= 10)
cents -= 10;
else if (cents >= 5)
cents -= 5 * nickels;
else if (cents >= 1)
cents -= 1;
System.out.println(cents + " cents = " + quarters + " quarters + " + dimes + " dimes + " + nickels + " nickels + " + pennies + " pennies");
Also, Im supposed to be using nested loops for these.
First of all, do you have any algorithm to find those all combination?
No. That is my main problem right now....Finding all the possible combinations.
Most probably you have to think about permutations. It's the easiest way to figure out the way of selections. Then try to convert them into steps.