Chinaunix首页 | 论坛 | 博客
  • 博客访问: 602979
  • 博文数量: 149
  • 博客积分: 7191
  • 博客等级: 少将
  • 技术积分: 1561
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-19 14:15
文章分类

全部博文(149)

文章存档

2013年(1)

2011年(2)

2010年(14)

2009年(29)

2008年(26)

2007年(31)

2006年(32)

2005年(14)

分类: C/C++

2005-12-19 15:16:28

 Program Make Change

// ****************************************************
// 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
   }
}

阅读(855) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~