【问题标题】:How can i make a entry into an array with an unknown size?我怎样才能进入一个未知大小的数组?
【发布时间】:2017-04-02 23:25:40
【问题描述】:

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

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

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


    }
} 

我有点困惑如何制作一个未知大小的数组?

感谢任何帮助和指导 谢谢你。

【问题讨论】:

  • 你可以使用ArrayList吗?
  • 这就是ArrayList 的用途。
  • 无论如何,为什么这么多人投反对票?这是他/她的第一个问题帖子。我觉得太严格了。

标签: java arrays


【解决方案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());

试试这是我小组的一个演示程序,它应该可以帮助您了解如何获取所需信息,因为那些真正知道该做什么的人似乎不会费心提供帮助。抱歉,我无法准确回答您的问题。

【讨论】:

    猜你喜欢
    • 2014-06-10
    • 1970-01-01
    • 2012-10-28
    • 2015-03-15
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    • 2019-08-06
    • 2020-04-06
    相关资源
    最近更新 更多