测试类
package Library; import java.util.Scanner; public class Tushuguan { public static void main(String[] args) { System.out.println("1-按照书名查询信息"+"2-按照序号查询信息"); try{ Scanner inqut=new Scanner(System.in); int num=inqut.nextInt();} catch(Exception e){ System.out.println("请输入数字1或者2进行查询"); System.out.println("请重新输入"); Scanner in = new Scanner(System.in); int sum=in.nextInt(); try{ switch(sum){ case 1: shuming one=new shuming(); String name1=one.Book(); break; } } catch(Exception a){ a.printStackTrace(); System.out.println("请输入正确的书名"+"\n请重新输入"); Scanner on = new Scanner(System.in); String name=on.next(); } }}}
shuming类
package Library; import java.util.Scanner; import java.util.Arrays; public class shuming { public String Book() throws Exception{ String [] book=new String[]{"Thank in Java","Head First In Java","C pro"}; System.out.println(Arrays.toString(book)); String name; try { Scanner inqut=new Scanner(System.in); name = inqut.next(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); throw e; } return name; } }
请问为什么我的测试类正常运行输入1的时候 程序就结束了
而输入出现错误的时候重新输入1 她才展示出来shuming类中的调用??
慕的地6079101
Z_Java
Z_Java
qq_hellohellola_03814043
相关分类