weixin_慕用1239336
2023-01-12 13:36
borrowBookjava.util.ScannerBorrowBook {
(String[] args) {
String[] bookList =String[]bookList[]=bookList[]=bookList[]=bookList[]=System..println()order=Scanner scanner=Scanner(System.){
order=scanner.nextInt()}(Exception e){
System..println()}
(order){
:
System..println()String bookNamebookName=scanner.next(){
(i=i<= bookList.i++)String book=bookList.get(i)(bookName.equals(book)){
System..println(+book)}
}(Exception e){
System..println()}
:
System..println()num={
num=scanner.nextInt()}(Exception e){
System..println()}
{
System..println(+bookList.get(num-))}(Exception e){
System..println()}
:
System..println()}
}
}
import java.util.Scanner; public class BorrowBook { public static void main(String[] args) { // 初始化图书列表 String[] bookList = {"Book1", "Book2", "Book3"}; Scanner scanner = new Scanner(System.in); int order = 0; try { System.out.println("请输入操作序号:"); order = scanner.nextInt(); } catch (Exception e) { System.out.println("输入有误:" + e.getMessage()); } switch (order) { case 1: System.out.println("请输入要借阅的图书名称:"); String bookName = scanner.next(); try { for (int i = 0; i < bookList.length; i++) { String book = bookList[i]; if (bookName.equals(book)) { System.out.println("借阅成功:" + book); } } } catch (Exception e) { System.out.println("出现异常:" + e.getMessage()); } break; case 2: System.out.println("请输入要借阅的图书序号:"); int num = 0; try { num = scanner.nextInt(); } catch (Exception e) { System.out.println("输入有误:" + e.getMessage()); } try { System.out.println("借阅成功:" + bookList[num - 1]); } catch (Exception e) { System.out.println("出现异常:" + e.getMessage()); } break; default: System.out.println("无效的操作序号"); break; } scanner.close(); } }
Java入门第三季
409776 学习 · 4546 问题
相似问题