Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

CalculateChange

By: a guest on Feb 21st, 2012  |  syntax: None  |  size: 0.63 KB  |  views: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }