为了账号安全,请及时绑定邮箱和手机立即绑定

发一下我的答案

public class ChaShu {

public static void main(String[] args) {

ChaShu cs = new ChaShu();

cs.FindBook();

}

public void FindBook() {

while(true) {

System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书");

Scanner sc = new Scanner(System.in);

try {

int i =sc.nextInt();

if(i==1) {

String bookname = null;

First(bookname );

}

if(i==2) {

int a = 0;

Second(a);

}else{

System.out.println("输入错误,请重新输入");

}

}catch(Exception e) {

System.out.println(e.getMessage());

}

}

}

public void First(String bookname) {

System.out.println("请输入图书名称:");

String book[] = {"高数","英语","语文"};

Scanner sc = new Scanner(System.in);

bookname = sc.nextLine();

try {

int a=1000000;

for(int i=0;i<book.length;i++) {

if(bookname.equals(book[i])) {

System.out.println("book:"+book[i]);

a=-1;

}

}

if(a==1000000) {

throw new Exception();

}

}catch(Exception e) {

System.out.println("图书不存在");

}

}

public void Second(int a) {

System.out.println("请输入图书id");

Scanner sc = new Scanner(System.in);

String book[] = {"高数","英语","语文"};

a = sc.nextInt();

if(a>0 && a<=book.length) {

System.out.println("book:"+book[a-1]);

}else {

System.out.println("图书不存在");

}

}

}


正在回答

1 回答

牛批!

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

发一下我的答案

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信