ChangeMoney

ChangeMoney - else if( change >= 50 ) quarters =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.Scanner; public class ChangeMoney { public static void main(String[] args) { int price; System.out.print("Enter price of item(from 0 cents to a dollar, in 5-cents increments)"); Scanner keyboard = new Scanner(System.in); price = keyboard.nextInt(); System.out.println("price = " + price); if ((price > 100) || (price < 0)) {System.out.print("!!! Invalid price");} else { int change = 100 - price; int quarters = 0; if( change >= 75 ) quarters = 3;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: else if( change &gt;= 50 ) quarters = 2; else if( change &gt;= 25 ) quarters = 1; change = change - 25 * quarters; int dimes = 0; if( change &gt;= 20 ) dimes = 2; else if( change &gt;=10 ) dimes = 1; change = change - 10 * dimes; int nickels = 0; if( change &gt;= 5 ) nickels = 1; System.out.println(quarters + &quot; quarters&quot;); System.out.println(dimes + &quot; dimes&quot;); System.out.println(nickels + &quot; nickels&quot;); } } }...
View Full Document

Ask a homework question - tutors are online