题解 | #判断学生成绩# 自定义异常 抛出
判断学生成绩
https://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(); //write your code here...... try { if (score >= 0 && score <= 100) //正常分数输出 System.out.println(score); else throw new ScoreException("分数不合法"); } catch (ScoreException s) { System.out.println(s.getMessage()); } } } class ScoreException extends Exception { //write your code here...... public ScoreException(String message) { super(message); } }
不符合条件抛出异常
Java语法基础 文章被收录于专栏
基础语法的熟悉