Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Roy & Omri on 12/24/2015.
- */
- import java.util.Scanner;
- public class Money {
- public static void main(String []args){
- Scanner UI = new Scanner(System.in);
- System.out.println("How much money do you have?");
- int money = UI.nextInt();
- int result = 0;
- int twohundredBill = 0;
- int hundredBill = 0;
- int fiftyBill = 0;
- int twentyBill = 0;
- int tenCoin = 0;
- int fiveCoin = 0;
- int twoCoin = 0;
- int oneCoin = 0;
- while(money > 0){
- if(money < 200){
- if(money < 100){
- if(money < 50){
- if(money < 20){
- if(money < 10){
- if(money < 5){
- if(money < 2){
- money -= 1;
- oneCoin += 1;
- }
- else {
- money -= 2;
- twoCoin += 1;
- }
- }
- else {
- money -= 5;
- fiveCoin += 1;
- }
- }
- else {
- money -= 10;
- tenCoin += 1;
- }
- }
- else{
- money -= 20;
- twentyBill += 1;
- }
- }
- else{
- money -= 50;
- fiftyBill += 1;
- }
- }
- else{
- money -= 100;
- hundredBill += 1;
- }
- }
- else{
- money -= 200;
- twohundredBill += 1;
- }
- }
- System.out.println("You can use " + twohundredBill + " Two Hundred Dollar Bills");
- System.out.println("You can use " + hundredBill + " Hundred Dollar Bills");
- System.out.println("You can use " + fiftyBill + " Fifty Dollar Bills");
- System.out.println("You can use " + twentyBill + " Twenty Dollar Bills");
- System.out.println("You can use " + tenCoin + " Coins of Ten");
- System.out.println("You can use " + fiveCoin + " Coins of Five");
- System.out.println("You can use " + twoCoin + " Coins of Two");
- System.out.println("You can use " + oneCoin + " Coins of One");
- }
- }
Add Comment
Please, Sign In to add comment