第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

java中排序更改為小數(shù)的問(wèn)題

java中排序更改為小數(shù)的問(wèn)題

一只甜甜圈 2023-09-20 16:24:34
您好,我需要幫助將零錢排序?yàn)樾?shù),如 25 美分、便士、鎳幣等。它說(shuō)可能有損轉(zhuǎn)換。這是我的代碼:public class Assignment04 {    public static void main(String[] args) {        Scanner stdin = new Scanner(System.in);        System.out.println("Enter your amount");        long amount = stdin.nextLong();        long remainder = Math.round(amount * 100 );        long hundreds = (int) remainder / 10000;        remainder = remainder % 10000;        long fifties = (int) remainder / 5000;        remainder = remainder % 5000;        long twenties = (int)remainder / 2000;        remainder = remainder % 2000;        long tens = (int)remainder / 1000;        remainder = remainder % 1000;        long fives = (int)remainder / 500;        remainder = remainder % 500;        long ones = (int)remainder / 100;        remainder = remainder % 100;        long quarters = remainder / .25;        remainder = remainder % .25;        long dimes =  (int)remainder / .10;        remainder = remainder % .10;        long nickels =  (int)remainder / .5;        remainder = remainder % .5;        double pennies = (int) remainder;        System.out.println(hundreds + "hundred/s");        System.out.println(fifties + "fiftie/s");        System.out.println(twenties + "twentie/s");        System.out.println(tens + "ten/s");        System.out.println(fives + "five/s");        System.out.println(ones + "one/s");        System.out.println(quarters + "quarter/s");        System.out.println(dimes + "dime/s");        System.out.println(nickels + "nickel/s");        System.out.println(pennies + "cent/s");    }}我試圖弄清楚如何刪除紅色下劃線,以便它可以正確運(yùn)行。我已經(jīng)完成了大部分工作,只是當(dāng)涉及到小數(shù)時(shí)我感到困惑。
查看完整描述

3 回答

?
慕標(biāo)5832272

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊

您的余數(shù)字段似乎以美分表示。

  • $100 = 10000

  • $20 = 2000

  • $1 = 100

因此,四分之一應(yīng)為 25,一角應(yīng)為 10,五分鎳應(yīng)為 5。

還要更改此:

double pennies = (int) remainder;

對(duì)此:

long pennies = remainder;

修復(fù)掃描儀輸入的 amount 并刪除所有最終存儲(chǔ)在 long 中的行的 (int) 轉(zhuǎn)換:

public class Assignment04 {

    public static void main(String[] args) {

        Scanner stdin = new Scanner(System.in);

        System.out.println("Enter your amount");

        long remainder = Math.round(stdin.nextDouble() * 100 );



        long hundreds = remainder / 10000;

        remainder = remainder % 10000;


        long fifties = remainder / 5000;

        remainder = remainder % 5000;


        long twenties = remainder / 2000;

        remainder = remainder % 2000;


        long tens = remainder / 1000;

        remainder = remainder % 1000;


        long fives = remainder / 500;

        remainder = remainder % 500;


        long ones = remainder / 100;

        remainder = remainder % 100;


        long quarters = remainder / 25;

        remainder = remainder % 25;


        long dimes = remainder / 10;

        remainder = remainder % 10;


        long nickels = remainder / 5;

        remainder = remainder % 5;


        long pennies = remainder;





        System.out.println(hundreds + "hundred/s");

        System.out.println(fifties + "fiftie/s");

        System.out.println(twenties + "twentie/s");

        System.out.println(tens + "ten/s");

        System.out.println(fives + "five/s");

        System.out.println(ones + "one/s");

        System.out.println(quarters + "quarter/s");

        System.out.println(dimes + "dime/s");

        System.out.println(nickels + "nickel/s");

        System.out.println(pennies + "cent/s");


    }

}


查看完整回答
反對(duì) 回復(fù) 2023-09-20
?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊

你可以使用 int 。而不是長(zhǎng)。我希望這有幫助。謝謝


Scanner stdin = new Scanner(System.in);

            int amount;

            int remainder;

            System.out.print("Enter amount:");

            amount= (int) Math.round(stdin.nextDouble() * 100);

            int hundreds= remainder / 1000;

                if (hundreds > 0) {

                    remainder = remainder% 1000;

                    System.out.println(hundreds + "hundred/s");

                }


     int fifties = remainder / 1000;

                        if (fifties > 0) {

                            remainder = remainder% 1000;

                            System.out.println(fifties + "fiftie/s");

                    }

                // number of twenties for remainder.

                int twenties = change / 2000

                if (twenties > 0) { 

                    remainder= remainder % 2000; // this resets the value of remainder to

                    // the remainder after the twenties are

                    // calculated but only if there was at

                    // least enough to make one twenty

                    System.out.println(twenties + "twentie/s");

                }


                int tens = remainder / 1000;

                if (tens > 0) {

                    remainder = remainder% 1000;

                    System.out.println(tens + " ten/s");

                }


                int fives = remainder/ 500;

                if (fives > 0) {

                    remainder= remainder% 500;

                    System.out.println(fives + " five/s");

                }


                int ones = remainder/ 100;

                if (ones > 0) {

                    remainder = remainder % 100;

                    System.out.println(ones + " one/s");

                }


                int quarters = remainder/ 25;

                if (quarters > 0) {

                    remainder= remainder% 25;

                    System.out.println(quarters + " quarter/s");

                }


                int dimes = remainder/ 10;

                if (dimes > 0) {

                    remainder = remainder % 10;

                    System.out.println(dimes + " dime/s");

                }


                int nickels = remainder/ 5;

                if (nickels > 0) {

                    remainder= change % 5;

                    System.out.println(nickels + " nickel/s");

                }

                int pennies = remainder;

                System.out.println(pennies + " cent/s");

            }


        }


查看完整回答
反對(duì) 回復(fù) 2023-09-20
?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊

我通過(guò)將金額和余數(shù)轉(zhuǎn)換為雙倍來(lái)修復(fù)它。



查看完整回答
反對(duì) 回復(fù) 2023-09-20
  • 3 回答
  • 0 關(guān)注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)