/* Change.java - Help the user make change. * Ask the user for the number of cents from 1-99, * and tell the user how many quarters, dimes, nickels and pennies * there should be. * The idea is that we use the / and % operators. First find the * number of quarters. Then, with the remaining money, figure the * dimes. From the remaining money, do the nickels and pennies * in a similar fashion. */ import java.util.Scanner; // for keyboard input public class Change { public static void main(String [] args) { // Input System.out.printf("Enter number of cents (1-99): "); Scanner sc = new Scanner(System.in); int cents = sc.nextInt(); // Calculations int quarters = cents / 25; int remainingMoney = cents % 25; int dimes = remainingMoney / 10; remainingMoney = remainingMoney % 10; int nickels = remainingMoney / 5; remainingMoney = remainingMoney % 5; int pennies = remainingMoney; // Output System.out.printf("\nYou have %d quarters, %d dimes\n", quarters, dimes); System.out.printf("%d nickels and %d pennies.\n", nickels, pennies); } }