Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
1.3 kB
2
Indexable
Never
import java.util.Scanner;

public class CoinsTwo {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        double balance = Double.parseDouble(scanner.nextLine());
        double sum = balance * 100;
        int coins = 0;

        while (sum > 0){
            if (sum / 200 >= 1){
                coins += sum / 200;
                sum -= (int)(sum / 200) * 200;
            }else if (sum / 100 >= 1){
                coins += sum / 100;
                sum -= (int)(sum / 100) * 100;
            }else if (sum / 50 >= 1){
                coins += sum / 50;
                sum -= (int)(sum / 50) * 50;
            }else if (sum / 20 >= 1){
                coins += sum / 20;
                sum -= (int)(sum / 20) * 20;
            }else if (sum / 10 >= 1){
                coins += sum / 10;
                sum -= (int)(sum / 10) * 10;
            }else if (sum / 5 >= 1){
                coins += sum / 5;
                sum -= (int)(sum / 5) * 5;
            }else if (sum / 2 >= 1){
                coins += sum / 2;
                sum -= (int)(sum / 2) * 2;
            }else{
                coins += sum;
                sum -= (int)(sum);
            }

        }

        System.out.println(coins);

    }
}