Skip to content

Instantly share code, notes, and snippets.

@BT-ICD
Created January 16, 2021 16:49
Show Gist options
  • Save BT-ICD/bd230d607cb7bb5d4cc9b026f457e058 to your computer and use it in GitHub Desktop.
Save BT-ICD/bd230d607cb7bb5d4cc9b026f457e058 to your computer and use it in GitHub Desktop.
Example of % (reminder) and integer division. Program to display various dollar bills required for particular dollar amount
/***
* American paper currency come in seven denominations: $1, $2, $5, $10, $20, $50, and $100.
* Write a program that display various dollar bills required for particular amount
*/
public class DollarBillsDemo {
public static void main(String[] args) {
int dollarAmount = 1285;
int d1,d2,d5,d10,d20,d50, d100, rem;
d100 = dollarAmount/100;
rem = dollarAmount%100;
d50 = rem/50;
rem%=50;
d20 = rem/20;
rem%=20;
d10 = rem/10;
rem%=10;
d5 = rem/5;
rem%=5;
d2 = rem/2;
rem%=2;
d1=rem;
System.out.println("Total Dollar Amount: " + dollarAmount);
System.out.println("100 dollar bills: " + d100);
System.out.println("50 dollar bills: " + d50);
System.out.println("20 dollar bills: " + d20);
System.out.println("10 dollar bills: " + d10);
System.out.println("5 dollar bills: " + d5);
System.out.println("2 dollar bills: " + d2);
System.out.println("1 dollar bills: " + d1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment