2017-04-02 105 views
-4

製作程序: - 向用戶詢問測試分數 - 創建分數數組 - 顯示最低分數 - 通過降低最低等級查找並調整平均分數。我怎樣才能進入一個未知大小的數組?

到目前爲止,這是我所:

public class AdjustingMarks 
{ 
    public static void main (String[] args) 
    { 
     Scanner scan = new Scanner (System.in); 

     // Get numbers from the keyboard 
     System.out.println("Please input your grade: "); 
     int mark = scan.readInt(); 


    } 
} 

我有點困惑,如何使一個數組的大小未知?

任何幫助和指導表示讚賞 謝謝。

+1

你允許使用'ArrayList'嗎? – ajb

+2

這是['ArrayList'](https://docs.oracle.com/javase/8/docs/api/index.html?java/util/ArrayList.html)的用途。 – Gendarme

+0

謝謝你的幫助 –

回答

-1
public class CalcAverage 
{ 
    public static void main(String[] args) 
    { 
     int numScores; // To hold the number of scores 

     // Create a Scanner object for keyboard input. 
     Scanner keyboard = new Scanner(System.in); 

     // Get the number of test scores. 
     System.out.print("How many test scores do you have? "); 
     numScores = keyboard.nextInt(); 

     // Create an array to hold the test scores. 
     double[] scores = new double[numScores]; 

     // Get the test scores and store them 
     // in the scores array. 
     for (int index = 0; index < numScores; index++) 
     { 
     System.out.print("Enter score #" + 
         (index + 1) + ": "); 
     scores[index] = keyboard.nextDouble(); 
     } 

     // Create a Grader object, passing the 
     // scores array as an argument to the 
     // constructor. 
     Grader myGrader = new Grader(scores); 

     // Display the adjusted average. 
     System.out.println("Your adjusted average is " + 
         myGrader.getAverage()); 

     // Display the lowest score. 
     System.out.println("Your lowest test score was " + 
         myGrader.getLowestScore()); 

試試這個它我組的演示程序,它應該幫助您得到的如何,因爲它似乎那些誰真正知道該怎麼做不會費心幫得到你所需要的信息的想法。對不起,我不能完全回答你的問題。