如何进入大小未知的数组?

时间:2017-04-02 23:25:41

标签: java arrays

制作一个程序: - 询问用户的考试成绩 - 为分数创建数组 - 显示最低分 - 通过降低最低等级来找到并调整平均分数。

到目前为止,这就是我所拥有的:

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 个答案:

答案 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());

尝试这个我的小组的演示程序它应该帮助你了解如何获得所需的信息,因为看起来那些真正知道该怎么做的人不会费心去帮忙。对不起,我无法完全回答你的问题。