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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java重復(fù)比較值與數(shù)組雙精度并在錯誤輸入后重復(fù)

Java重復(fù)比較值與數(shù)組雙精度并在錯誤輸入后重復(fù)

Go
胡說叔叔 2022-11-30 11:13:18
當用戶輸入價值支付率時,它會檢查價值支付率與支付率數(shù)組。如果正確,那么它會提示用戶是否需要完成另一個過程。如果沒有,它將去計算。如果支付率錯誤,則顯示錯誤并要求用戶重新輸入值。我有問題,在用戶按下“Y”后,它會顯示“錯誤的支付率,請重試”。public static void main(String[] args) {    //Scanner    Scanner read = new Scanner(System.in);    //Array of payRate Default    double[] payRateDefault = {3.50, 4.00, 4.50, 4.75, 5.00, 5.25, 5.50, 5.75, 6.00};    double payRateEntered;    boolean isPayRate = false;    char anotherProcess;    System.out.print("Enter hours work: ");    int hoursWork = read.nextInt();    do {        System.out.print("Enter pay rate: ");        payRateEntered = read.nextDouble();        for (int i = 0; i < payRateDefault.length; i++) {            if (payRateDefault[i] == payRateEntered) {                //If the payRate is true with array payRateDefault, proceed to ask if you have another employee                System.out.println("Do you have any employee to process (Y/N)");                anotherProcess = read.next().charAt(0);                isPayRate = true;                //Check if Y or N                switch (anotherProcess) {                    case 'Y':                        //Proceed back to prompt user to enter pay rate                        break;                    case 'N':                        //Proceed to calculation                        break;                    default:                        //If wrong input                        System.out.println("Please use Y or N only");                        break;                }            } else {                isPayRate = false;            }        }        System.out.println("You have entered the wrong pay rate. Please try again");    } while (!isPayRate);}結(jié)果:
查看完整描述

2 回答

?
隔江千里

TA貢獻1906條經(jīng)驗 獲得超10個贊

以下代碼對我來說很好用:


package mm.com.java.so.test;


import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;


public class JavaRepeat {


    public static void main(String[] args) throws IOException {


        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));


        double[] defaultPayRates = { 3.50, 4.00, 4.50, 4.75, 5.00, 5.25, 5.50, 5.75, 6.00 };


        double payRate;

        boolean isValid;

        boolean isContinue;

        String next;

        int workingHour;


        do {


            isValid = false;

            isContinue = false;


            System.out.print("\nEnter hours work : ");


            workingHour = Integer.parseInt(reader.readLine());


            do {


                System.out.print("Enter pay rate: ");


                payRate = Double.parseDouble(reader.readLine());


                for (int i = 0; i < defaultPayRates.length; i++) {


                    if (defaultPayRates[i] == payRate) {

                        isValid = true;

                        // TODO : make calculation here.

                        break;

                    }

                }


                if (!isValid) {

                    System.out.println("You have entered the wrong pay rate. Please try again !!!");

                }


            } while (!isValid);


            do {


                isValid = true;


                System.out.println("\nDo you have any employee to process (Y/N)");


                next = reader.readLine();


                switch (next.toLowerCase()) {

                    case "y":

                        isContinue = true;

                        break;


                    case "n":

                        isContinue = false;

                        break;


                    default:

                        isValid = false;

                        System.out.println("Please use Y or N only.");

                        break;

                }

            } while (!isValid);


        } while (isContinue);


        // TODO : print out calculation here.


        System.out.println("\nCalculation is doing. Please wait...");

    }

}

我的測試結(jié)果如下:


Enter hours work : 3

Enter pay rate: 2

You have entered the wrong pay rate. Please try again !!!

Enter pay rate: 5


Do you have any employee to process (Y/N)

y


Enter hours work : 2

Enter pay rate: 5


Do you have any employee to process (Y/N)

z

Please use Y or N only.


Do you have any employee to process (Y/N)

N


Calculation is doing. Please wait...


查看完整回答
反對 回復(fù) 2022-11-30
?
梵蒂岡之花

TA貢獻1900條經(jīng)驗 獲得超5個贊

僅當is時,您才應(yīng)該執(zhí)行該System.out.println("You have entered the wrong pay rate. Please try again");行。 isPayRatefalse


boolean finished = false;

do {

    System.out.print("Enter pay rate: ");

    payRateEntered = read.nextDouble();


    for (int i = 0; i < payRateDefault.length; i++) {


        if (payRateDefault[i] == payRateEntered) {


            //If the payRate is true with array payRateDefault, proceed to ask if you have another employee

            System.out.println("Do you have any employee to process (Y/N)");

            anotherProcess = read.next().charAt(0);

            isPayRate = true;


            //Check if Y or N

            switch (anotherProcess) {

                case 'Y':

                    //Proceed back to prompt user to enter pay rate


                    break;

                case 'N':

                    //Proceed to calculation

                    finished = true;

                    break;

                default:

                    //If wrong input

                    System.out.println("Please use Y or N only");

                    break;

            }

            break;

        } else {

            isPayRate = false;

        }

    }

    if (!isPayRate) {

        System.out.println("You have entered the wrong pay rate. Please try again");

    }

} while (!finished);


查看完整回答
反對 回復(fù) 2022-11-30
  • 2 回答
  • 0 關(guān)注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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