Skip to content

Instantly share code, notes, and snippets.

@joeyv
Created October 11, 2013 17:34
Show Gist options
  • Save joeyv/6938832 to your computer and use it in GitHub Desktop.
Save joeyv/6938832 to your computer and use it in GitHub Desktop.
Simple program to calculate change .
import java.util.Scanner;
public class Change
{
public static void main(String []args){
int cent, placeholder; //placeholder is to store the remainder number
int quarter, dime, nickel, penny;
Scanner scan = new Scanner(System.in);
//User input
cent = scan.nextInt();
//User input devided by the value of a qurter first because it holds the highest value
//placeholder is to keep the value of the remainder for the next step in the equation.
quarter = cent / 25;
placeholder = cent % 25;
//The remainder (placeholder) will be divided by the value of a dime.
//Then it will be checked for a remainder and continue the procces until the lowest value, penny
dime = placeholder / 10;
placeholder = placeholder % 10;
nickel = placeholder / 5;
placeholder = placeholder % 5;
penny = placeholder / 1;
//print
System.out.println ("Quarters:" + quarter + "\nDimes:" + dime + "\nNickels:" + nickel + "\nPennies:" + penny);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment