java 弹出多行输入框_Java使用Scanner读取多行输入跳出问题

在Java中使用Scanner读取多行输入时,遇到读取完整数后跳过下一行的问题。通过在读取完JPay后添加`in.nextLine()`,解决了跳过JDes读取的问题,确保了程序正常运行。
摘要由CSDN通过智能技术生成

源代码如下:

Scanner in = new Scanner(System.in);

System.out.println("Pls insert Title");

ja.setJTitle(in.nextLine());

System.out.println("Pls insert Number");

ja.setJNumber(in.nextInt());

System.out.println("Pls insert Pay");

ja.setJPay(in.nextInt());

System.out.println("Pls insert Description");

ja.setJDes(in.nextLine());

in.close();

Job.displayInfo();

程序在读取JPay后运行println后自动跳过JDes读取,直接至dispalyInfo

运行结果如:

1290170222011031552.htm

经过参考帖子:http://blog.csdn.net/xiao_niu_1/article/details/8240650 后修改代码为:

Scanner in = new Scanner(System.in);

System.out.println("Pls insert Title");

ja.setJTitle(in.nextLine());

System.out.println("Pls insert Number");

ja.setJNumber(in.nextInt());

System.out.println("Pls insert Pay");

ja.setJPay(in.nextInt());

in.nextLine();

System.out.println("Pls insert Description");

ja.setJDes(in.nextLine());

in.close();

Job.displayInfo();

在读取JPay后添加in.nextLine()

运行结果:

1290170222011031552.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值