Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Fun;
- public class CalculateChange {
- public static void main(String[] args){
- double amount = 43.87;
- int remainingAmount = (int)(amount *100);
- int dollars = remainingAmount/100;
- remainingAmount%= 100;
- int quarters = remainingAmount/25;
- remainingAmount%= 25;
- int dimes = remainingAmount/10;
- remainingAmount%= 10;
- int nickels = remainingAmount/5;
- remainingAmount%= 5;
- int pennies = remainingAmount;
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement