慕先生7064480
2019-10-20 16:52
package booktest;
import java.util.Scanner;
public class book {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean n = true;
String[] bookname = new String[] {"高数","数据结构"};
while(n)
{
try {
Scanner input = new Scanner(System.in);
System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书");
int number = input.nextInt();
if(number == 1){
System.out.println("输入图书名称:");
Scanner input1 = new Scanner(System.in);
String a = input1.nextLine();
for(String b:bookname) {
if(b.contains(a)) {
System.out.println("book:"+ a);
break;
}
else {
System.out.println("图书不存在!");
break;
}
}
}
else if(number ==2){
System.out.println("输入图书序号:");
int c = input.nextInt();
if(c == 0) {
System.out.println("book:" + bookname[c]);
break;
}
else if(c == 1) {
System.out.println("book:" + bookname[1]);
break;
}
else {
System.out.println("图书不存在!");
}
}
}catch(Exception e){
System.out.println("命令输入错误!请根据提示输入数字命令!");
continue;
}
}
}
}
这是不是应该发表在笔记里比较合适。这已经是第二个要我回答的分享帖了
Java入门第三季
409792 学习 · 4340 问题
相似问题