ChangeMoney

ChangeMoney - else if change>= 50 quarters = 2 else if...

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 >= 50 ) quarters = 2; else if( change >= 25 ) quarters = 1; change = change - 25 * quarters; int dimes = 0; if( change >= 20 ) dimes = 2; else if( change >=10 ) dimes = 1; change = change - 10 * dimes; int nickels = 0; if( change >= 5 ) nickels = 1; System.out.println(quarters + " quarters"); System.out.println(dimes + " dimes"); System.out.println(nickels + " nickels"); } } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online