package tushu; public class Shu extends Tushu{ public Shu(int id,String name){ this.name=name; this.id=id; } }
package tushu; public class Tushu { int id; String name; }
package tushu; import java.util.Scanner; public class Use { public static void main(String[] args) { // TODO 自动生成的方法存根 Tushu Tushu[] = { new Shu(1,"数学"), new Shu(2,"语文"), new Shu(3,"英语"), new Shu(4,"物理") }; System.out.println("输入命令:/t1:按照名称查找图书/t2:按照序号查找图书"); Scanner input = new Scanner(System.in); int id=input.nextInt(); if(id==1){ System.out.print("输入书名:"); String ru=input.next(); for(int i=0;i<Tushu.length;i++){ if(Tushu[i].name.equals(ru)){ System.out.println("book:"+Tushu[i].name); System.exit(0); } } System.out.println("图书不存在"); Use.main(args); }else if(id==2){ System.out.print("输入序号:"); int e=input.nextInt(); for(int i=0;i<Tushu.length;i++){ if(Tushu[i].id==e){ System.out.println("book:"+Tushu[i].name); System.exit(0); } } System.out.println("图书不存在"); Use.main(args); }else{ System.out.println("输入错误,请根据提示输入。"); Use.main(args); } } }
能正常运行,但是异常处理,用try{}catch(){}包围不会,求指导
慕勒0069038
慕妹5461943
风中打伞的小孩
相关分类