全部博文(149)
分类: C/C++
2005-12-19 15:16:28
// ****************************************************
// Program Make Change: Given any amount of change
// expressed in cents, this program computes the number
// of half-dollars, quarters, dimes, nickels, and
// pennies to be returned, returning as many
// half-dollars as possible, then quarters, dimes,
// nickels, and pennies in that order.
//*****************************************************
import java.io.*;
public class MakeChange
{
static BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));
static final int HALFDOLLAR = 50;
static final int QUARTER = 25;
static final int DIME = 10;
static final int NICKEL = 5;
public static void main (String[] args) throws IOException
{
//declare variables
int change;
//Statements: Step 1 - Step 12
System.out.print("Enter the change in cents: "); //Step 1
System.out.flush();
change = Integer.parseInt(keyboard.readLine()); //Step 2
System.out.println();
System.out.println("The change you entered is "
+ change); //Step 3
System.out.println("The number of half dollars "
+ "to be returned are "
+ change / HALFDOLLAR); //Step 4
change = change % HALFDOLLAR; //Step 5
System.out.println("The number of quarters to be "
+ "returned are "
+ change / QUARTER); //Step 6
change = change % QUARTER; //Step 7
System.out.println("The number of dimes to be "
+ "returned are "
+ change / DIME); //Step 8
change = change % DIME; //Step 9
System.out.println("The number of nickels to be "
+ "returned are "
+ change / NICKEL); //Step 10
change = change % NICKEL; //Step 11
System.out.println("The number of pennies to be "
+ "returned are " + change); //Step 12
}
}