/****************************************************************** * Program Make Change * * Description: Determine the fewest coins needed to represent * a certain amount of change. * * Input: An amount of change in cents * * Output: The distribution of the fewest coins to make * up the given amount of change. * ******************************************************************/ import java.io.*; import java.util.Scanner; public class MakeChange { // constants static final int HALFDOLLAR = 50, QUARTER = 25, DIME = 10, NICKEL = 5; //static final int QUARTER = 25; //static final int DIME = 10; //static final int NICKEL = 5; public static void main (String[] args) throws IOException { Scanner scan = new Scanner(System.in); // declare variables int change; // ask the user for input System.out.print ("Enter the change in cents: "); change = scan.nextInt(); System.out.println ("\nYou entered " + change + " cents in change. That is"); // how many half dollars? System.out.println (change / HALFDOLLAR + " half dollars,"); change = change % HALFDOLLAR; // how many quarters? System.out.println (change / QUARTER + " quarters,"); change = change % QUARTER; // how many dimes? System.out.println (change / DIME + " dimes,"); change = change % DIME; // how many nickels? System.out.println (change / NICKEL + " nickels, and"); change = change % NICKEL; // we're left with pennies System.out.println (change + " pennies."); } // end of main method } // end of class MakeChange