题解 | #判断学生成绩#
判断学生成绩
http://www.nowcoder.com/practice/a35cbafbec10449f8a576e822430a3ab
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int score = scanner.nextInt();
try{
if(score>=0&&score<=100)//正常分数输出
System.out.println(score);
else
throw new ScoreException("分数不合法");//抛出异常
}
catch (ScoreException str)
{
System.out.println(str.getMessage());//输出异常
}
}
}
class ScoreException extends Exception {//继承自异常类的分数异常处理类
public ScoreException(String message)//构造函数
{
super(message);//输出异常函数
}
}
查看8道真题和解析