Change whole money for change

The code is as follows:

/*Change the whole money. If there is a decimal point 2.94, it shows how many 1 yuan, 5 Mao, 2 Mao, 1 Mao, 5 points, 2 points and 1 point * / import Java util. Scanner; Class demo3 {public static void main (string [] args) {scanner SC = new scanner (system. In); system. Out. Println ("please enter the change amount"); double money = sc.nextdouble(); / / because the decimal is inaccurate, you need to convert the money in yuan into int sumfen = (int) (money * 100) ; // Total money in cents / / calculate the number of pieces of int yiyuannum = sumfen / 100 first; sumFen =sumFen%100; // Remaining balance after finding a piece int wumaonum = sumfen / 50; sumFen=sumFen%50; // The remaining balance after finding 20 cents int ermaonum = sumfen / 20; sumFen=sumFen%20; // Remaining balance after finding 1 Mao int yimaonum = sumfen / 10; sumFen=sumFen%10; // Remaining balance after finding 1 Gross int wufennum = sumfen / 5; sumFen=sumFen%5; // The remaining balance after finding 5 points int erfennum = sumfen / 2; sumFen=sumFen%2; // Find the remaining balance of 2 points. / / the remaining amount in sumfen is 1 point system out. Println ("the number of 1 yuan is:" + yiyuannum); System. out. Println ("the number of fifty cents is:" + wumaonum); System. out. Println ("the number of 20 cents is:" + ermaonum); System. out. Println ("the number of Dimes is:" + yimaonum); System. out. Println ("the number of 5 cents is:" + wufennum); System. out. Println ("the number of 2 cents is:" + erfennum); System. out. Println ("the number of cents is:" + sumfen);}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>