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

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

如何添加雙精度命令以給出小數(shù)平均值

如何添加雙精度命令以給出小數(shù)平均值

慕森卡 2023-06-21 14:58:29
我正在嘗試編寫代碼,對 3 個輸入的帶小數(shù)的測試分?jǐn)?shù)進(jìn)行平均。當(dāng)我輸入 double 命令時,它給了我一個錯誤。它在沒有雙重命令的情況下運行良好,但是當(dāng)我嘗試添加它時它不起作用,我試圖在線查看但找不到任何東西。請幫忙import java.util.Scanner;class FirstLab{    public static void main(String[] args) //header of the main method    {  Scanner in = new Scanner(System.in);        int test1 , test2 , test3;        int double NUM_TEST= 3;        System.out.print("Input first test: "); // user prompt        test1 = in.nextInt(); // read in the next integer        System.out.print("Input second test: "); // user prompt        test2 = in.nextInt();        System.out.print("Input third test: "); // user prompt        test3 = in.nextInt();        System.out.println("Average test score is: " +   (test3 + test2 + test1) / double(NUM_TEST);  }}this is the error message:C:\Users\Guestt\Desktop\CSE\FirstLab.java:18: error: not a statement        int double NUM_TEST= 3;        ^C:\Users\Guestt\Desktop\CSE\FirstLab.java:18: error: ';' expected        int double NUM_TEST= 3;           ^C:\Users\Guestt\Desktop\CSE\FirstLab.java:30: error: '.class' expected   (test3 + test2 + test1) / double(NUM_TEST);                                   ^C:\Users\Guestt\Desktop\CSE\FirstLab.java:30: error: ';' expected   (test3 + test2 + test1) / double(NUM_TEST);                                    ^C:\Users\Guestt\Desktop\CSE\FirstLab.java:30: error: illegal start of expression   (test3 + test2 + test1) / double(NUM_TEST);                                            ^5 errorsTool completed with exit code 1
查看完整描述

1 回答

?
呼如林

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

首先,變量NUM_TEST聲明為int double;只需書寫double就足夠了。


另外,在最后的 print 語句中,有一個不匹配的左括號;引用變量名也可以,NUM_TEST不用寫double(NUM_TEST)


以下代碼稍作修改,應(yīng)該可以正常工作:


Scanner in = new Scanner(System.in);

int test1 , test2 , test3;

double NUM_TEST= 3;

System.out.print("Input first test: "); // user prompt

test1 = in.nextInt(); // read in the next integer

System.out.print("Input second test: "); // user prompt

test2 = in.nextInt();

System.out.print("Input third test: "); // user prompt

test3 = in.nextInt();

System.out.println("Average test score is: " + (test3 + test2 + test1) / (NUM_TEST));

:)


查看完整回答
反對 回復(fù) 2023-06-21
  • 1 回答
  • 0 關(guān)注
  • 197 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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