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

为什么不能在控制台输入书名

为什么不能在控制台输入书名

Meng7y 2017-06-13 20:30:56
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 "高数": System.out.println(new Book().getBook1()); break; case "数据结构": System.out.println(new Book().getBood2()); break; default: Test.a = false; break; } } }}
查看完整描述

1 回答

已采纳
?
botao555

TA贡献48条经验 获得超46个赞

String b = input1.toString();

把这行换成:

String b = input1.nextLine();

input1.nextLine(); 才是读取控制台输入的一行字符串。

查看完整回答
1 反对 回复 2017-06-14
  • 1 回答
  • 0 关注
  • 1359 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信