我是JAVA和Netbeans的新手。这是我要做的:
显示每个级别(R,1、2、3、4)中的学生人数。

Level R (mark < 50)
Level 1 ( (mark >= 50) && (mark < 60) )
Level 2 ( (mark >= 60) && (mark < 70) )
Level 3 ( (mark >= 70) && (mark < 80) )
Level 4 (mark >= 80).


我需要使用一个数组,并且我知道它需要包含5个元素。我不知道该怎么做。但是,我不希望您知道整个代码,所以请不要关闭问题。我只想知道一个提示或方法,所以我知道如何编写程序。感谢您的帮助,在此先感谢您!

最佳答案

这是一些让您入门的东西

    Point2D levelContainer[] = new Point2D[5];
    //set the R level
    levelContainer[0] = new Point2D.Double(0, 50);
    //set the rest
    levelContainer[1] = new Point2D.Double(50, 60);
    levelContainer[2] = new Point2D.Double(60, 70);
    levelContainer[3] = new Point2D.Double(70, 80);
    levelContainer[4] = new Point2D.Double(80, Double.MAX_VALUE);

    double exampleMark[] = {2, 56, 63, 70, 8080};

    for(int index = 0; index < exampleMark.length; index++)
    {
        //now for every mark we have, we need to loop the level array until we find the which level it falls in
        for(int levelIndex = 0; levelIndex < levelContainer.length; levelIndex++)
        {
            //now check the X, our minimum value, and the Y,our max value, for our range and if it does fall into the range print out the level
            if(exampleMark[index] >= levelContainer[levelIndex].getX() && exampleMark[index] < levelContainer[levelIndex].getY())
            {
                //basically use R if the level the mark falls into is 0
                String level = levelIndex == 0 ? "R" : new Integer(levelIndex).toString();
                System.out.println("Our current mark is " + exampleMark[index] + " which falls between "
                        + levelContainer[levelIndex].getX() + " and " +
                        levelContainer[levelIndex].getY() + " which is level " + level);
            }
        }
    }

10-06 10:19