交作业(图书查询)
public class Initial {
public static void main(String[] args) {
String[] library = {"xml","ssm","数据结构与算法"};
int n = 0;
while (true) {
try {
Scanner scanner = new Scanner(System.in);
String tipString = "图书不存在!";
System.out.println("输入命令:1-按书名查找 2-按编号查找");
n = scanner.nextInt();
if (n==1) {
try {
System.out.println("请输入书名:");
String name = scanner.next();
for (int i = 0; i < library.length; i++) {
if (name.equals(library[i])) {
tipString = "book:"+name;
break;
}
}
} catch (Exception e) {
continue;
} finally {
System.out.println(tipString);
}
}else if (n==2) {
System.out.println("请输入编号:");
try {
int num = scanner.nextInt();
tipString = "book:"+library[num];
System.out.println(tipString);
}catch (Exception e) {
System.out.println("请输入数值");
continue;
}
}
} catch (Exception e) {
System.out.println("根据提示输入正确命令!");
continue;
}
}
}
}