package com.imooc; import java.util.*; public class Return { public static void main(String[] args) { // TODO Auto-generated method stub String[] book={"数学分析","高等代数","数理统计","回归分析","多元统计","时间序列","随机过程"}; int[] num={1,2,3,4,5,6,7}; Return cw=new Return(); System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书"); Scanner input=new Scanner(System.in); String xz; int xh; while(true) { xz=input.next(); try{ int pd=Integer.parseInt(xz); if (pd!=1&&pd!=2){ RuntimeException a=new RuntimeException(); throw a; } //System.out.println("输入正确了"); break; }catch(RuntimeException e){ System.out.println("命令输入错误!请根据提示输入数字命令"); continue; } } if(xz.equals("1")){ System.out.println("请输入图书名称"); while(true){ String sm=input.next(); //System.out.println("刚才输入的是"+sm); try{ for (int i=0;i<book.length;i++){ if(sm.equals(book[i])){ System.out.println("find book:"+book[i]); break; }else if (i<6) continue; else if(i==6) { //cw.zbds(); RuntimeException e=new RuntimeException(); throw e; } } break; }catch(RuntimeException e){ System.out.println("图书不存在!请重新输入"); continue; } } }else if(xz.equals("2")){ while(true){ System.out.println("请输入图书序号:"); try{ xh=input.nextInt(); if(xh>=1&&xh<=7){ System.out.println("find book:"+book[xh-1]); break; }else { RuntimeException a=new RuntimeException(); throw a; } }catch(RuntimeException a){ System.out.println("命令输入错误!请根据提示输入数字命令"); continue; } } } } }
Frank_W毅3947945
相关分类