Created
October 11, 2013 17:29
-
-
Save imryan/6938754 to your computer and use it in GitHub Desktop.
Calculates change.
This file contains hidden or 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; | |
| class Hello { | |
| public static void main(String[] args) { | |
| // Declare variables | |
| Scanner sc = new Scanner(System.in); | |
| final int QUARTER = 25; | |
| final int DIME = 10; | |
| final int NICKEL = 5; | |
| final int PENNY = 1; | |
| int cents = 0; | |
| int total = 0; | |
| int totalQuarters = 0; | |
| int totalDimes = 0; | |
| int totalNickels = 0; | |
| int totalPennies = 0; | |
| // Get input | |
| cents = sc.nextInt(); | |
| // Calculate values | |
| totalQuarters = cents / QUARTER; | |
| cents %= QUARTER; | |
| totalDimes = cents / DIME; | |
| cents %= DIME; | |
| totalNickels = cents / NICKEL; | |
| cents %= NICKEL; | |
| totalPennies = cents / PENNY; | |
| cents %= PENNY; | |
| System.out.println("Quarters:\t" + totalQuarters); | |
| System.out.println("Dimes:\t" + totalDimes); | |
| System.out.println("Nickels:\t" + totalNickels); | |
| System.out.println("Pennies:\t" + totalPennies); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment