我是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个元素。我不知道该怎么做。但是,我不希望知道你的整个代码,所以不要关闭这个问题。我想知道的只是提示或方法,所以我知道如何编写程序。我感谢任何帮助,并提前感谢您!
答案 0 :(得分:1)
这是让你入门的东西
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);
}
}
}