Calculate coins (Java)

Write a program to read the double value that represents the total amount entered by the user, print the minimum number of banknotes and coins required to represent the amount, and print starting from the maximum amount. The types of banknotes are ten yuan, five yuan, and one yuan, and the types of coins are five cents, one dime, two cents, and one cent.

Input format:
47.63

Output format:
4 sheets of ten yuan,
1 sheet of five yuan,
2 sheets of one yuan,
1 five
-corner,
1 one -corner, 1 two-point,
1 one-point

Input sample:
Here is a set of input. E.g:

47.63

Output sample:
The corresponding output is given here. E.g:

4 pieces of ten yuan,
1 piece of five yuan,
2 pieces of one yuan,
1 pentagon,
1 dime,
1 two minute,
1 one minute

import java.util.Scanner;

public class Main {
    
    
    public static void main(String[] args) {
    
    
        Scanner sc=new Scanner(System.in);
        double n = sc.nextDouble();
        System.out.println((int)n/10+" 张十元");
        System.out.println((int)n%10/5+" 张五元");
        System.out.println((int)n%10%5/1+" 张一元");
        double a =n%10%5%1;
        System.out.println((int)(a/0.5)+" 张五毛");
        System.out.println((int)(a%0.5/0.1)+" 张一毛");
        double b=a%0.5%0.1;
        System.out.println((int)(b/0.02)+" 张二分");
        System.out.println((int)(b%0.02/0.01)+" 张一分");
    }
}

Guess you like

Origin blog.csdn.net/weixin_51430516/article/details/115048423