Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ex05Coins {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double input = Double.parseDouble(scanner.nextLine());
- input *= 100;
- int income = (int)input;
- int coinCounter = 0;
- while (income > 0) {
- if (income >= 200) {
- income -= 200;
- coinCounter++;
- } else if (income >= 100) {
- income -= 100;
- coinCounter++;
- } else if (income >= 50) {
- income -= 50;
- coinCounter++;
- } else if (income >= 20) {
- income -= 20;
- coinCounter++;
- } else if (income >= 10) {
- income -= 10;
- coinCounter++;
- } else if (income >= 5) {
- income -= 5;
- coinCounter++;
- } else if (income >= 2) {
- income -= 2;
- coinCounter++;
- } else {
- income -= 1;
- coinCounter++;
- }
- }
- System.out.println(coinCounter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement