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

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

通過數組傳遞不確定量的Int

通過數組傳遞不確定量的Int

富國滬深 2021-05-06 18:49:09
我在一個Java編程入門課程中,我試圖弄清楚如何從用戶輸入的Int數組中填充一個數組。我已經看過我教授的所有視頻,并做了很多Google搜索,但我一直無法弄清楚。import java.util.Scanner;public class GradesForClass {    public static void main(String[] args) {        Scanner keyboard = new Scanner(System.in);        System.out.println("Hello Drews, how many total grades do you want to process?");        int numberOfGrades = keyboard.nextInt();        int sum = 0;        for (int i = 0; i < numberOfGrades; i++) {            System.out.println("Please enter grade " + (i + 1) + ": ");            int userGradeNumbers = keyboard.nextInt();            sum += userGradeNumbers;                    }        int storeGrades[] = new int[userGradeNumbers];        int totalScore = sum;        //int lowestScore = ;        //int highestScore = ;        double averageScore = sum / (double) numberOfGrades;        System.out.println("Total score is: " + totalScore);        //System.out.println("Lowest score is: " + lowestScore);        //System.out.println("Highest score is: " + highestScore);        System.out.println("Average score is: " + averageScore);        keyboard.close();    }}
查看完整描述

2 回答

?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

由于您知道將要處理多少個成績,因此最簡單的方法是開始要求用戶輸入之前先創(chuàng)建一個數組。

int[] storeGrades = new int[numberOfGrades];

而不是用戶輸入之后(您當前所在的位置)。

有了該名稱后,就可以使用從0到的數字來引用數組的元素numberOfGrades - 1。特別是在輸入數字的循環(huán),

storeGrades[i] = userGradeNumbers;

因為i是精確遍歷您所需范圍的索引。


查看完整回答
反對 回復 2021-05-19
  • 2 回答
  • 0 關注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號