Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Sample Run:
- * Please Enter the Amount Paid:
- * 5.00
- * Please Enter the Cost of the Item:
- * 4.57
- * Change Owed: 0.43
- * Pennies: 3
- * Nickels: 1
- * Dimes: 1
- * Quarters: 1
- *
- */
- import java.io.*;
- import static java.lang.System.*;
- import java.util.Scanner;
- import java.lang.Math;
- class Main{
- public static void main (String str[]) throws IOException {
- Scanner scan = new Scanner (System.in);
- System.out.println("Please Enter the Amount Paid:");
- double x = scan.nextDouble();
- System.out.println("Please Enter the Cost of the Item:");
- double y = scan.nextDouble();
- double z = ((double)((Math.round(x * 1000)) - (Math.round(y * 1000)))/1000);
- int pennies = ((int)((100*z))%5);
- int quarters = (int)((z*100)/25);
- int dimes = (int)(((z*100)-quarters*25)/10);
- int nickels = (int)(((z*100)-(quarters*25)-(dimes*10))/5);
- System.out.println("Change Owed: " + z);
- System.out.println("Pennies: " + pennies);
- System.out.println("Nickels: " + nickels );
- System.out.println("Dimes: " + dimes);
- System.out.println("Quarters: " + quarters);
- scan.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement