public class Test { public static boolean a; public void ex() throws MyException{ if (a == false){ throw new MyException("輸入有誤,請重新輸入"); } } public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("輸入1表示按照書名查找書籍,輸入2表示按照書的序號查找書籍"); Scanner input = new Scanner(System.in); int a = input.nextInt(); if (a == 1){ System.out.println("請輸入書籍名稱"); Scanner input1 = new Scanner(System.in); String b = input1.toString(); switch (b) { case "高數(shù)": System.out.println(new Book().getBook1()); break; case "數(shù)據(jù)結(jié)構(gòu)": System.out.println(new Book().getBood2()); break; default: Test.a = false; break; } } }}
1 回答
已采納

botao555
TA貢獻(xiàn)48條經(jīng)驗 獲得超46個贊
String?b?=?input1.toString();
把這行換成:
String?b?=?input1.nextLine();
input1.nextLine(); 才是讀取控制臺輸入的一行字符串。
添加回答
舉報
0/150
提交
取消