public class score {
public static void main(String[] args) {
Scanner as = new Scanner(System.in);
int score1 = as.nextInt();
if (score1 > 0 && score1 <100) {
System.out.println("成绩输入正确");
}
else {
throw new Scoreexception("成绩输入错误");
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class Scoreexception extends RuntimeException{
public Scoreexception(String message) {
super(message);
}
}
1
2
3
4
5
6
运行结果:
-2
Exception in thread "main" day_16.Scoreexception: 成绩输入错误
at day_16.score.main(score.java:13)