2017-04-02 63 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()); 

试试这个它我组的演示程序,它应该帮助您得到的如何,因为它似乎那些谁真正知道该怎么做不会费心帮得到你所需要的信息的想法。对不起,我不能完全回答你的问题。