小编Ale*_*ria的帖子

这是使用IllegalArgumentException的正确方法吗?

我正在尝试从事Java任务.这是它要求的:

写一个名为的类TestScores.类构造函数应该接受一组测试分数作为其参数.该类应该有一个返回测试分数平均值的方法.如果数组中的测试分数为负或大于100,则该类应该抛出一个IllegalArgumentException.演示.我需要一个名为TestScoresand 的文件TestScoresDemo.

这就是我到目前为止所拥有的.我知道其中有些是错的,我需要帮助修复它:

class TestScores {
    public static void checkscore(int s) {
        if (s<0) throw new IllegalArgumentException("Error: score is negative.");
        else if (s>100) throw new IllegalArgumentException("Error Score is higher then 100");
        else if (s>89)throw new IllegalArgumentException("Your grade is an A");
        else if (s>79 && s<90)throw new IllegalArgumentException("Your grade is an B");
        else if (s>69 && s<80)throw new IllegalArgumentException("Your grade is an C");
        else if (s>59 && s<70)throw new IllegalArgumentException("Your grade is …
Run Code Online (Sandbox Code Playgroud)

java exception illegalargumentexception

7
推荐指数
1
解决办法
9万
查看次数

标签 统计

exception ×1

illegalargumentexception ×1

java ×1