【牛客带你学编程Java方向】项目练习第5期(参考答案)
参考答案:
public class Programme3 {
public static void main(String[] args){
Player player=new Player();
try {
player.play(11);
} catch (NoThisSoundException e) {
System.out.println(e.getMessage());
}
}
}
class NoThisSoundException extends Exception{
NoThisSoundException(){
super();
}
NoThisSoundException(String message){
super(message);
}
}
class Player{
void play(int index) throws NoThisSoundException{
if(index>10){
throw new NoThisSoundException("您播放的歌曲不存在");
}
}
}
Tips:
牛客带你学编程-Java方向:【牛客带你学编程】【Java方向】0基础小白入门培养计划!
