Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- File : Change.java
- Author: G.J. Grevera
- Desc. : Purchase an item and make change.
- */
- import java.util.Scanner;
- public class Change {
- public static void main ( String args[] ) {
- //get ready to read from the keyboard
- Scanner in = new Scanner( System.in );
- //prompt for the price
- System.out.print( "Enter price of an item: " );
- //get the price
- int price = in.nextInt();
- //calculate change
- int change = 100 - price;
- int quarters = change / 25;
- change = change - quarters * 25;
- int dimes = change / 10;
- change = change - dimes * 10;
- int nickels = change / 5;
- //report results (change)
- System.out.println( "You bought an item for " + price +
- " cents and gave me a dollar so your change is:" );
- System.out.println( "\t" + quarters + " quarters," );
- System.out.println( "\t" + dimes + " dimes, and" );
- System.out.println( "\t" + nickels + " nickels" );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement