Created
October 11, 2013 17:34
-
-
Save joeyv/6938832 to your computer and use it in GitHub Desktop.
Simple program to calculate change .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
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