gpt4 book ai didi

java - 确定每个级别的学生人数

转载 作者:行者123 更新时间:2023-12-01 09:11:25 25 4
gpt4 key购买 nike

我是 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);
}
}
}

关于java - 确定每个级别的学生人数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40900172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com