Advertisement
Guest User

CalculateChange

a guest
Feb 21st, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. package Fun;
  2.  
  3. public class CalculateChange {
  4. public static void main(String[] args){
  5.  
  6. double amount = 43.87;
  7. int remainingAmount = (int)(amount *100);
  8. int dollars = remainingAmount/100;
  9. remainingAmount%= 100;
  10. int quarters = remainingAmount/25;
  11. remainingAmount%= 25;
  12. int dimes = remainingAmount/10;
  13. remainingAmount%= 10;
  14. int nickels = remainingAmount/5;
  15. remainingAmount%= 5;
  16. int pennies = remainingAmount;
  17.  
  18. System.out.printf("Your amount %5.2f consists of \n"+"%d dollars \n"+"%d quarters \n"+"%d dimes \n"+"%d nickels \n"+"%d pennies \n",amount,dollars,quarters,dimes,nickels,pennies);
  19.  
  20.  
  21.  
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement